Skip to content

widenDealias before extracting namedTupleElementTypes #20505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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