File tree Expand file tree Collapse file tree 5 files changed +74
-1
lines changed
compiler/src/scala/quoted/runtime/impl Expand file tree Collapse file tree 5 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,9 @@ class QuoteMatcher(debug: Boolean) {
139139 // After matching and doing all subtype checks, we have to approximate all the type bindings
140140 // that we have found, seal them in a quoted.Type and add them to the result
141141 val typeHoleApproximations = typeHoles.map(typeHoleApproximation)
142- val matchedTypes = typeHoleApproximations.map(tpe => new TypeImpl (TypeTree (tpe), spliceScope))
142+ val matchedTypes = typeHoleApproximations.map { tpe =>
143+ new TypeImpl (TypeTree (tpe).withSpan(scrutinee.span), spliceScope)
144+ }
143145 val matchedExprs =
144146 val typeHoleMap : Type => Type =
145147 if typeHoles.isEmpty then identity
Original file line number Diff line number Diff line change 1+ // Macros.scala
2+ import Main ._
3+ import scala .quoted .*
4+
5+ object Macros {
6+ inline def apply (): ProviderProcessor =
7+ $ { Macros .processorExpr }
8+
9+ def processorExpr [I : Type ](using q : Quotes ): Expr [ProviderProcessor ] = ' {
10+ new ProviderProcessor {
11+ override def apply (simple : Simple ): MyF [Int ] =
12+ $ { Macros .methodProcessorImpl(' simple ) }
13+ }
14+ }
15+
16+ def methodProcessorImpl [I : Type ](using q : Quotes )(service : Expr [Simple ]): Expr [MyF [Int ]] = {
17+ import q .reflect ._
18+
19+ val returnType = TypeRepr .of[Int ]
20+ returnType.asType match {
21+ case ' [rt] =>
22+ ' {
23+ $ {
24+ import quotes .reflect ._
25+ TypeApply (
26+ Select .unique(' { ??? .asInstanceOf [Codec ] }.asTerm, " apply" ),
27+ List (TypeTree .of[rt]) // generates the error, directly using Int instead of rt makes it disappear
28+ ).asExpr
29+ }
30+ ???
31+ }
32+ }
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ // Main.scala
2+ object Main {
3+ type MyF [A ]
4+
5+ trait ProviderProcessor {
6+ def apply (simple : Simple ): MyF [Int ]
7+ }
8+
9+ trait Codec {
10+ def apply [A ]: MyF [A ]
11+ }
12+
13+ trait Simple {
14+ def a0 : Int
15+ }
16+
17+ def test (): Unit = {
18+ val p = Macros ()
19+ }
20+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ @ main def run () =
2+ println(Macro .foo)
You can’t perform that action at this time.
0 commit comments