Skip to content

Commit

Permalink
Widen singleton types when computing fields from .Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Dec 5, 2024
1 parent 6a08590 commit 4839206
Show file tree
Hide file tree
Showing 2 changed files with 19 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 @@ -868,7 +868,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
&& pt != LhsProto
then
val pre = if !TypeOps.isLegalPrefix(qual.tpe) then SkolemType(qual.tpe) else qual.tpe
val fieldsType = pre.select(tpnme.Fields).dealias.simplified
val fieldsType = pre.select(tpnme.Fields).widenDealias.simplified
val fields = fieldsType.namedTupleElementTypes
typr.println(i"try dyn select $qual, $selName, $fields")
fields.find(_._1 == selName) match
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i22018.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scala.language.experimental.namedTuples

class SelectableNT[A <: NamedTuple.AnyNamedTuple](val nt: A) extends Selectable:
type Fields = A
def selectDynamic(x: String) = ???

object Test:

val a = (name = "foo", age = 1)

val sa = SelectableNT(a)
sa.name // ok

type B = a.type
val b: B = a

val sb = SelectableNT(b)
sb.name // fails

0 comments on commit 4839206

Please sign in to comment.