Skip to content

Drop EmptyTuple handling from NamedTupleDecomposition.apply #22340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
EugeneFlesselle committed Jan 10, 2025
commit d11d6f67c2aca761387e2a6d3ada0ec53862fdef
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
Loading