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 #20512: Try implicit searching after finding dynamic select #22318

Merged
merged 2 commits into from
Jan 8, 2025
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
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
else EmptyTree

def dynamicSelect(pt: Type) =
val tree2 = cpy.Select(tree0)(untpd.TypedSplice(qual), selName)
if pt.isInstanceOf[FunOrPolyProto] || pt == LhsProto then
assignType(tree2, TryDynamicCallType)
else
typedDynamicSelect(tree2, Nil, pt)
val tree2 = cpy.Select(tree0)(untpd.TypedSplice(qual), selName)
if pt.isInstanceOf[FunOrPolyProto] || pt == LhsProto then
assignType(tree2, TryDynamicCallType)
else
typedDynamicSelect(tree2, Nil, pt)

// Otherwise, if the qualifier derives from class Dynamic, expand to a
// dynamic dispatch using selectDynamic or applyDynamic
Expand Down Expand Up @@ -885,7 +885,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
// Reject corner case where selectDynamic needs annother selectDynamic to be called. E.g. as in neg/unselectable-fields.scala.
report.error(i"Cannot use selectDynamic here since it needs another selectDynamic to be invoked", tree.srcPos)
case _ =>
dynSelected.ensureConforms(fieldType)
adapt(dynSelected, defn.AnyType).ensureConforms(fieldType)
case _ => EmptyTree
else EmptyTree

Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ i18211.scala
10867.scala
named-tuples1.scala
i20897.scala
i20512.scala

# Opaque type
i5720.scala
Expand Down
26 changes: 26 additions & 0 deletions tests/pos/i20512.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import language.experimental.namedTuples

import NamedTuple.*

trait Selector1 extends Selectable {
type Fields = (int: Int, str: String)

def selectDynamic(name: String)(using name.type <:< Tuple.Union[NamedTuple.Names[Fields]]) = ???
}

def test20512 = {
val s: Selector1 = new Selector1 {}
val int = s.int
val str = s.str
}

trait Ctx

class Selector2 extends Selectable:
type Fields = (bar: Int, baz: Int)
def selectDynamic(fieldName: String)(using Ctx): Any = ???

def test22023(using Ctx) =
val f = Selector2()
val bar = f.bar
val baz = f.baz
Loading