Skip to content

Commit

Permalink
Drop EmptyTuple handling from NamedTupleDecomposition.apply
Browse files Browse the repository at this point in the history
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
  • Loading branch information
EugeneFlesselle committed Jan 13, 2025
1 parent 5369d1a commit 74aa123
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions library/src/scala/NamedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i22324.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74aa123

Please sign in to comment.