Skip to content

Commit

Permalink
widenDealias before extracting namedTupleElementTypes (#20505)
Browse files Browse the repository at this point in the history
@odersky perhaps you have a better suggestion?

fixes #20439
  • Loading branch information
odersky authored Jun 2, 2024
2 parents cfc51b0 + 32e3969 commit c6fbe6f
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 c6fbe6f

Please sign in to comment.