From d11d6f67c2aca761387e2a6d3ada0ec53862fdef Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Fri, 10 Jan 2025 17:32:15 +0100 Subject: [PATCH] Drop `EmptyTuple` handling from `NamedTupleDecomposition.apply` We previously needed to handle the case where the result of `toTuple` was an `EmptyTuple` separately from the rest, since `apply` used to be only defined for `NonEmptyTuple`s. This was changed in #21291, making the inline match in `NamedTupleDecomposition.apply` no longer necessary. The underlying issue with the proxies introduced to handle opaque types with inline defs is likely still present. Nevertheless, it is probably best to fix this specific instance of the problem with NamedTuples as soon as possible. Fixes #22324 --- library/src/scala/NamedTuple.scala | 4 +--- tests/pos/i22324.scala | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i22324.scala diff --git a/library/src/scala/NamedTuple.scala b/library/src/scala/NamedTuple.scala index 6da7f940dc47..0d1deffce513 100644 --- a/library/src/scala/NamedTuple.scala +++ b/library/src/scala/NamedTuple.scala @@ -139,9 +139,7 @@ object NamedTupleDecomposition: extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V]) /** The value (without the name) at index `n` of this tuple */ inline def apply(n: Int): Elem[NamedTuple[N, V], n.type] = - inline x.toTuple match - case tup: NonEmptyTuple => tup(n).asInstanceOf[Elem[NamedTuple[N, V], n.type]] - case tup => tup.productElement(n).asInstanceOf[Elem[NamedTuple[N, V], n.type]] + x.toTuple.apply(n).asInstanceOf[Elem[NamedTuple[N, V], n.type]] /** The number of elements in this tuple */ inline def size: Size[NamedTuple[N, V]] = x.toTuple.size diff --git a/tests/pos/i22324.scala b/tests/pos/i22324.scala new file mode 100644 index 000000000000..b35f82d52ac9 --- /dev/null +++ b/tests/pos/i22324.scala @@ -0,0 +1,10 @@ +import scala.language.experimental.namedTuples + +opaque type System = (wires: Any) + +extension (system: System) + inline def foo = system.wires +end extension + +val simulation: System = ??? +val _ = simulation.foo // was error