Skip to content

Commit

Permalink
Fix #20512: Try implicit searching after finding dynamic select (#22318)
Browse files Browse the repository at this point in the history
Fix #20512
  • Loading branch information
noti0na1 authored Jan 8, 2025
2 parents dc0bb59 + 200548e commit 15ea35b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
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

0 comments on commit 15ea35b

Please sign in to comment.