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

Fix NamedTuple selection on an unstable prefix #20455

Merged
merged 1 commit into from
May 23, 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
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if qual.tpe.derivesFrom(defn.SelectableClass) && !isDynamicExpansion(tree)
&& !pt.isInstanceOf[FunOrPolyProto] && pt != LhsProto
then
val fieldsType = qual.tpe.select(tpnme.Fields).dealias.simplified
val pre = if !TypeOps.isLegalPrefix(qual.tpe) then SkolemType(qual.tpe) else qual.tpe
val fieldsType = pre.select(tpnme.Fields).dealias.simplified
val fields = fieldsType.namedTupleElementTypes
typr.println(i"try dyn select $qual, $selName, $fields")
fields.find(_._1 == selName) match
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/named-tuple-unstable.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import scala.language.experimental.namedTuples
import NamedTuple.{AnyNamedTuple, NamedTuple}

trait Foo extends Selectable:
val f: Any
type Fields = (myfield: f.type)
def selectDynamic(name: String): Any

object Test:
val elem1: Foo { val f: Int } = ???
def elem2: Foo { val f: Int } = ???

def test: Unit =
val a: Int = elem1.myfield // OK
val b: Int = elem2.myfield // error: value myfield is not a member of Foo { val f: Int }
Loading