From 8246cb93486cf6b3b7215aec5ad45ed972d6fee4 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Wed, 16 Jul 2025 13:35:21 +0000 Subject: [PATCH] Use base types to compute classOf args of applyDynamic As suggested in https://github.com/scala/scala3/issues/11043#issuecomment-820518493 Fixes #11043 --- compiler/src/dotty/tools/dotc/typer/Dynamic.scala | 2 +- tests/pos/i11043.scala | 14 ++++++++++++++ tests/pos/i11043min.scala | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i11043.scala create mode 100644 tests/pos/i11043min.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Dynamic.scala b/compiler/src/dotty/tools/dotc/typer/Dynamic.scala index 14cc7bf963a6..18ba94260d14 100644 --- a/compiler/src/dotty/tools/dotc/typer/Dynamic.scala +++ b/compiler/src/dotty/tools/dotc/typer/Dynamic.scala @@ -268,7 +268,7 @@ trait Dynamic { if tpe.paramInfoss.nestedExists(!TypeErasure.hasStableErasure(_)) then fail(i"has a parameter type with an unstable erasure") :: Nil else - TypeErasure.erasure(tpe).asInstanceOf[MethodType].paramInfos.map(clsOf(_)) + tpe.paramInfoss.flatten.map(tp => clsOf(tp.baseType(tp.classSymbol))) structuralCall(nme.applyDynamic, classOfs).maybeBoxingCast(tpe.finalResultType) } diff --git a/tests/pos/i11043.scala b/tests/pos/i11043.scala new file mode 100644 index 000000000000..955350c71091 --- /dev/null +++ b/tests/pos/i11043.scala @@ -0,0 +1,14 @@ +import scala.reflect.Selectable.reflectiveSelectable + +object Test { + type Runner = { def run(args: Array[String]): Unit } + + def test(args: Array[String], runner: Runner): Unit = + runner.run(args) + + def main(args: Array[String]): Unit = { + test(Array("foo", "bar"), new { + def run(args: Array[String]): Unit = args foreach println + }) + } +} diff --git a/tests/pos/i11043min.scala b/tests/pos/i11043min.scala new file mode 100644 index 000000000000..89b8005387e4 --- /dev/null +++ b/tests/pos/i11043min.scala @@ -0,0 +1,5 @@ +import scala.reflect.Selectable.reflectiveSelectable + +type Runner = { def run(args: Array[String]): Unit } + +def test(runner: Runner): Unit = runner.run(???)