diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index c941ffe74e18..76b853c4aabd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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 @@ -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 diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index f35d527edf62..23c79affada0 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -70,6 +70,7 @@ i18211.scala 10867.scala named-tuples1.scala i20897.scala +i20512.scala # Opaque type i5720.scala diff --git a/tests/pos/i20512.scala b/tests/pos/i20512.scala new file mode 100644 index 000000000000..d30a3df9fc7c --- /dev/null +++ b/tests/pos/i20512.scala @@ -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 \ No newline at end of file