Skip to content

Commit 74aa123

Browse files
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
1 parent 5369d1a commit 74aa123

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: library/src/scala/NamedTuple.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ object NamedTupleDecomposition:
139139
extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V])
140140
/** The value (without the name) at index `n` of this tuple */
141141
inline def apply(n: Int): Elem[NamedTuple[N, V], n.type] =
142-
inline x.toTuple match
143-
case tup: NonEmptyTuple => tup(n).asInstanceOf[Elem[NamedTuple[N, V], n.type]]
144-
case tup => tup.productElement(n).asInstanceOf[Elem[NamedTuple[N, V], n.type]]
142+
x.toTuple.apply(n).asInstanceOf[Elem[NamedTuple[N, V], n.type]]
145143

146144
/** The number of elements in this tuple */
147145
inline def size: Size[NamedTuple[N, V]] = x.toTuple.size

Diff for: tests/pos/i22324.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import scala.language.experimental.namedTuples
2+
3+
opaque type System = (wires: Any)
4+
5+
extension (system: System)
6+
inline def foo = system.wires
7+
end extension
8+
9+
val simulation: System = ???
10+
val _ = simulation.foo // was error

0 commit comments

Comments
 (0)