Skip to content

Commit a3c4bd2

Browse files
committed
Add missing span in QuoteMatcher
Fixes #18155
1 parent 66b6dff commit a3c4bd2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class QuoteMatcher(debug: Boolean) {
135135
// After matching and doing all subtype checks, we have to approximate all the type bindings
136136
// that we have found, seal them in a quoted.Type and add them to the result
137137
val typeHoleApproximations = typeHoles.map(typeHoleApproximation)
138-
val matchedTypes = typeHoleApproximations.map(tpe => new TypeImpl(TypeTree(tpe), spliceScope))
138+
val matchedTypes = typeHoleApproximations.map { tpe =>
139+
new TypeImpl(TypeTree(tpe).withSpan(scrutinee.span), spliceScope)
140+
}
139141
val matchedExprs =
140142
val typeHoleMap: Type => Type =
141143
if typeHoles.isEmpty then identity

tests/pos-macros/i18155/Macro_1.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted.*
2+
3+
object Macro:
4+
transparent inline def foo: Any = ${ fooImpl }
5+
6+
def fooImpl(using Quotes): Expr[Any] =
7+
import quotes.reflect.*
8+
'{
9+
val xxx = ${
10+
Type.of[Int] match
11+
case '[tpe] =>
12+
Typed(Expr(1).asTerm, TypeTree.of[tpe]).asExpr
13+
}
14+
xxx
15+
}

tests/pos-macros/i18155/Test_2.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@main def run() =
2+
println(Macro.foo)

0 commit comments

Comments
 (0)