diff --git a/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala b/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala index 90ee82ebe5bf..4983243a2f84 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala @@ -135,7 +135,9 @@ class QuoteMatcher(debug: Boolean) { // After matching and doing all subtype checks, we have to approximate all the type bindings // that we have found, seal them in a quoted.Type and add them to the result val typeHoleApproximations = typeHoles.map(typeHoleApproximation) - val matchedTypes = typeHoleApproximations.map(tpe => new TypeImpl(TypeTree(tpe), spliceScope)) + val matchedTypes = typeHoleApproximations.map { tpe => + new TypeImpl(TypeTree(tpe).withSpan(scrutinee.span), spliceScope) + } val matchedExprs = val typeHoleMap: Type => Type = if typeHoles.isEmpty then identity diff --git a/tests/pos-macros/i17610/Macros.scala b/tests/pos-macros/i17610/Macros.scala new file mode 100644 index 000000000000..974bf3a53a59 --- /dev/null +++ b/tests/pos-macros/i17610/Macros.scala @@ -0,0 +1,34 @@ +// Macros.scala +import Main._ +import scala.quoted.* + +object Macros { + inline def apply(): ProviderProcessor = + ${ Macros.processorExpr } + + def processorExpr[I: Type](using q: Quotes): Expr[ProviderProcessor] = '{ + new ProviderProcessor { + override def apply(simple: Simple): MyF[Int] = + ${ Macros.methodProcessorImpl('simple) } + } + } + + def methodProcessorImpl[I: Type](using q: Quotes)(service: Expr[Simple]): Expr[MyF[Int]] = { + import q.reflect._ + + val returnType = TypeRepr.of[Int] + returnType.asType match { + case '[rt] => + '{ + ${ + import quotes.reflect._ + TypeApply( + Select.unique('{ ???.asInstanceOf[Codec] }.asTerm, "apply"), + List(TypeTree.of[rt]) // generates the error, directly using Int instead of rt makes it disappear + ).asExpr + } + ??? + } + } + } +} diff --git a/tests/pos-macros/i17610/Test.scala b/tests/pos-macros/i17610/Test.scala new file mode 100644 index 000000000000..7c745537e0c9 --- /dev/null +++ b/tests/pos-macros/i17610/Test.scala @@ -0,0 +1,20 @@ +// Main.scala +object Main { + type MyF[A] + + trait ProviderProcessor { + def apply(simple: Simple): MyF[Int] + } + + trait Codec { + def apply[A]: MyF[A] + } + + trait Simple { + def a0: Int + } + + def test(): Unit = { + val p= Macros() + } +} diff --git a/tests/pos-macros/i18155/Macro_1.scala b/tests/pos-macros/i18155/Macro_1.scala new file mode 100644 index 000000000000..598d739bc02d --- /dev/null +++ b/tests/pos-macros/i18155/Macro_1.scala @@ -0,0 +1,15 @@ +import scala.quoted.* + +object Macro: + transparent inline def foo: Any = ${ fooImpl } + + def fooImpl(using Quotes): Expr[Any] = + import quotes.reflect.* + '{ + val xxx = ${ + Type.of[Int] match + case '[tpe] => + Typed(Expr(1).asTerm, TypeTree.of[tpe]).asExpr + } + xxx + } diff --git a/tests/pos-macros/i18155/Test_2.scala b/tests/pos-macros/i18155/Test_2.scala new file mode 100644 index 000000000000..743643da5aba --- /dev/null +++ b/tests/pos-macros/i18155/Test_2.scala @@ -0,0 +1,2 @@ +@main def run() = + println(Macro.foo)