Skip to content

Commit

Permalink
fix: Change the NamedTuple.apply method to transparent inline
Browse files Browse the repository at this point in the history
This fixes a problem with not being able to reference named tuple fields
immediately from a named tuple literal
  • Loading branch information
KacperFKorban committed Sep 27, 2024
1 parent d490d13 commit 739b40e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/src/scala/NamedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ object NamedTupleDecomposition:
import NamedTuple.*
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): Tuple.Elem[V, n.type] =
transparent inline def apply(n: Int): Tuple.Elem[V, n.type] =
inline x.toTuple match
case tup: NonEmptyTuple => tup(n).asInstanceOf[Tuple.Elem[V, n.type]]
case tup => tup.productElement(n).asInstanceOf[Tuple.Elem[V, n.type]]
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i21413.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//> using scala 3.nightly

import scala.language.experimental.namedTuples

val x = (aaa = 1).aaa

0 comments on commit 739b40e

Please sign in to comment.