Skip to content
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

Widen singleton types when computing fields from .Fields #22149

Merged
merged 1 commit into from
Dec 10, 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 @@ -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
Loading