From 32e39698efd00dd3ddc3d72f62fc1f432d82d5c0 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Fri, 31 May 2024 15:46:50 +0200 Subject: [PATCH] widenDealias before extracting namedTupleElementTypes --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/pos/named-tuple-selections.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/pos/named-tuple-selections.scala 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