From 739b40ee48503a23b0dcddc837ad0429f8e2a5f6 Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Tue, 17 Sep 2024 11:44:55 +0200 Subject: [PATCH] fix: Change the NamedTuple.apply method to transparent inline This fixes a problem with not being able to reference named tuple fields immediately from a named tuple literal --- library/src/scala/NamedTuple.scala | 2 +- tests/pos/i21413.scala | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i21413.scala diff --git a/library/src/scala/NamedTuple.scala b/library/src/scala/NamedTuple.scala index 21c4c6840f5c..a7599b3418cf 100644 --- a/library/src/scala/NamedTuple.scala +++ b/library/src/scala/NamedTuple.scala @@ -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]] diff --git a/tests/pos/i21413.scala b/tests/pos/i21413.scala new file mode 100644 index 000000000000..4aa03573990e --- /dev/null +++ b/tests/pos/i21413.scala @@ -0,0 +1,6 @@ +//> using scala 3.nightly + +import scala.language.experimental.namedTuples + +val x = (aaa = 1).aaa +