Skip to content

Commit c6fbe6f

Browse files
authored
widenDealias before extracting namedTupleElementTypes (#20505)
@odersky perhaps you have a better suggestion? fixes #20439
2 parents cfc51b0 + 32e3969 commit c6fbe6f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
756756
return typedSelect(tree, pt, qual)
757757

758758
// Otherwise, try to expand a named tuple selection
759-
val namedTupleElems = qual.tpe.widen.namedTupleElementTypes
759+
val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes
760760
val nameIdx = namedTupleElems.indexWhere(_._1 == selName)
761761
if nameIdx >= 0 && Feature.enabled(Feature.namedTuples) then
762762
return typed(
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.language.experimental.namedTuples
2+
3+
object Test1:
4+
// original code from issue https://github.com/scala/scala3/issues/20439
5+
val bar = (a = 1, b = 2)
6+
7+
type ThatBar = bar.type
8+
val thatBar: ThatBar = bar
9+
val thatBar2: bar.type = bar
10+
11+
def test2 = thatBar.a // error
12+
def test3 = thatBar2.a // ok

0 commit comments

Comments
 (0)