Skip to content

Commit

Permalink
widenDealias before extracting namedTupleElementTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed May 31, 2024
1 parent 01b404f commit 32e3969
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/named-tuple-selections.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 32e3969

Please sign in to comment.