diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 24d28aa8b4e6..c11a0d1f15d6 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -756,7 +756,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer return typedSelect(tree, pt, qual) // Otherwise, try to expand a named tuple selection - val namedTupleElems = qual.tpe.widen.namedTupleElementTypes + val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes val nameIdx = namedTupleElems.indexWhere(_._1 == selName) if nameIdx >= 0 && Feature.enabled(Feature.namedTuples) then return typed( diff --git a/tests/pos/named-tuple-selections.scala b/tests/pos/named-tuple-selections.scala new file mode 100644 index 000000000000..c3569f21b323 --- /dev/null +++ b/tests/pos/named-tuple-selections.scala @@ -0,0 +1,12 @@ +import scala.language.experimental.namedTuples + +object Test1: + // original code from issue https://github.com/scala/scala3/issues/20439 + val bar = (a = 1, b = 2) + + type ThatBar = bar.type + val thatBar: ThatBar = bar + val thatBar2: bar.type = bar + + def test2 = thatBar.a // error + def test3 = thatBar2.a // ok