From 4e2a2e1d0bcf0a4b2a8652312a6be99a97644301 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 22 Sep 2025 19:43:15 +0200 Subject: [PATCH 1/4] Make typeArgs in QuotesImpl work for AnnotatedTypes Fixes #24006 --- .../src/scala/quoted/runtime/impl/QuotesImpl.scala | 1 + tests/neg-macros/i23008.check | 2 +- tests/run-macros/i24006/Eval.scala | 11 +++++++++++ tests/run-macros/i24006/Test.scala | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/run-macros/i24006/Eval.scala create mode 100644 tests/run-macros/i24006/Test.scala diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 87a865f81e1a..542e841b948f 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1829,6 +1829,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def typeArgs: List[TypeRepr] = self match case AppliedType(_, args) => args + case AnnotatedType(parent, _) => parent.typeArgs case _ => List.empty end extension end TypeReprMethods diff --git a/tests/neg-macros/i23008.check b/tests/neg-macros/i23008.check index 7c6140c8b2d7..52e2c42d24b0 100644 --- a/tests/neg-macros/i23008.check +++ b/tests/neg-macros/i23008.check @@ -5,8 +5,8 @@ | Exception occurred while executing macro expansion. | java.lang.IllegalArgumentException: requirement failed: value of StringConstant cannot be `null` | at scala.Predef$.require(Predef.scala:337) + | at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2424) | at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2423) - | at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2422) | at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:80) | at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:78) | at scala.quoted.Expr$.apply(Expr.scala:70) diff --git a/tests/run-macros/i24006/Eval.scala b/tests/run-macros/i24006/Eval.scala new file mode 100644 index 000000000000..f32a066e4c40 --- /dev/null +++ b/tests/run-macros/i24006/Eval.scala @@ -0,0 +1,11 @@ + +import scala.quoted._ + +object Eval: + + inline def eval[T](x: List[T]) = ${ evalImpl[T]('x) } + def evalImpl[A](x: Expr[List[A]])(using Quotes): Expr[Unit] = + import quotes.reflect.* + println(x.asTerm.tpe.widen) + x.asTerm.tpe.widen.typeArgs.head + '{()} diff --git a/tests/run-macros/i24006/Test.scala b/tests/run-macros/i24006/Test.scala new file mode 100644 index 000000000000..f9d3223b9811 --- /dev/null +++ b/tests/run-macros/i24006/Test.scala @@ -0,0 +1,3 @@ +import Eval.eval + +@main def Test() = eval(List(1) :+ 4) From 0ad362ee587be9a52e1303d66380c77aa7c0da52 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 3 Nov 2025 12:33:18 +0100 Subject: [PATCH 2/4] Make typeArgs in QuotesImpl work for AnnotatedTypes Fixes #24006 [Cherry-picked 3f108585d358205b569728930ed28abb8e9a772b][modified] From 4937d26e84b8132d9bc49fa0c849d582331388dc Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 22 Sep 2025 21:28:26 +0200 Subject: [PATCH 3/4] Add case for FlexibleType --- tests/new/test.scala | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/new/test.scala diff --git a/tests/new/test.scala b/tests/new/test.scala new file mode 100644 index 000000000000..a55b76a6ed30 --- /dev/null +++ b/tests/new/test.scala @@ -0,0 +1,7 @@ +object e: + def foldRL(f: Int => Int)(g: String => Int) = ??? + + +val xs = e.foldRL(i => i + 1)(s => s.length) + + From 2eaf15a083662a526546e3dbb7413bdd54b97b6a Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 3 Nov 2025 12:38:24 +0100 Subject: [PATCH 4/4] Add case for FlexibleType [Cherry-picked 925d7496f6670643ef1af9a0f14411eca3b628e1][modified]