Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing span in QuoteMatcher #18178

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/pos-macros/i17610/Macros.scala
Original file line number Diff line number Diff line change
@@ -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
}
???
}
}
}
}
20 changes: 20 additions & 0 deletions tests/pos-macros/i17610/Test.scala
Original file line number Diff line number Diff line change
@@ -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()
}
}
15 changes: 15 additions & 0 deletions tests/pos-macros/i18155/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions tests/pos-macros/i18155/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@main def run() =
println(Macro.foo)