@@ -2,10 +2,15 @@ package dotty.tools.dotc
2
2
package transform
3
3
4
4
import core ._
5
- import Decorators ._ , Flags ._ , Types ._ , Contexts ._ , Symbols ._ , Constants ._
5
+ import Decorators ._
6
+ import Flags ._
7
+ import Types ._
8
+ import Contexts ._
9
+ import Symbols ._
10
+ import Constants ._
6
11
import Flags ._
7
12
import ast .Trees ._
8
- import ast .{TreeTypeMap , untpd }
13
+ import ast .{TreeTypeMap , tpd , untpd }
9
14
import util .Positions ._
10
15
import tasty .TreePickler .Hole
11
16
import SymUtils ._
@@ -120,12 +125,19 @@ class ReifyQuotes extends MacroTransformWithImplicits {
120
125
new Reifier (isQuote, this , if (isQuote) level + 1 else level - 1 , levels, nestedEmbedded)
121
126
}
122
127
128
+ def inlined : Reifier = {
129
+ assert(level == 0 )
130
+ new Reifier (true , this , 0 , levels, embedded)
131
+ }
132
+
123
133
/** We are in a `~(...)` context that is not shadowed by a nested `'(...)` */
124
134
def inSplice : Boolean = outer != null && ! inQuote
125
135
126
136
/** We are not in a `~(...)` or a `'(...)` */
127
137
def isRoot : Boolean = outer == null
128
138
139
+ def isInlined : Boolean = inQuote && level == 0
140
+
129
141
/** A map from type ref T to expressions of type `quoted.Type[T]`".
130
142
* These will be turned into splices using `addTags` and represent type variables
131
143
* that can be possibly healed.
@@ -422,10 +434,27 @@ class ReifyQuotes extends MacroTransformWithImplicits {
422
434
spliceOutsideQuotes(splice.pos)
423
435
splice
424
436
}
425
- else {
437
+ else if (level > 0 ) {
426
438
val (body1, quotes) = nested(isQuote = false ).split(splice.qualifier)
427
439
makeHole(body1, quotes, splice.tpe).withPos(splice.pos)
428
440
}
441
+ else if (isInlined) {
442
+ // FIXME
443
+ val evaluatedSplice = Splicer .splice(splice.qualifier, splice.qualifier.pos, macroClassLoader).withPos(splice.qualifier.pos)
444
+ if (ctx.reporter.hasErrors) EmptyTree
445
+ else transform(evaluatedSplice)
446
+ } else {
447
+ if (! Splicer .canBeSpliced(splice.qualifier))
448
+ ctx.error( // TODO adapt error message
449
+ """ Malformed inline macro.
450
+ |
451
+ |Expected the ~ to be at the top of the RHS:
452
+ | inline def foo(x: X, ..., y: Y): Int = ~impl(x, ... '(y))
453
+ |
454
+ |The contents of the splice must call a static method. Arguments must be quoted or inlined.
455
+ """ .stripMargin, splice.pos)
456
+ splice
457
+ }
429
458
}
430
459
431
460
/** Transforms the contents of a nested splice
@@ -550,37 +579,10 @@ class ReifyQuotes extends MacroTransformWithImplicits {
550
579
val last = enteredSyms
551
580
stats.foreach(markDef)
552
581
mapOverTree(last)
553
- case Inlined (call, bindings, InlineSplice (spliced)) =>
554
- val tree2 =
555
- if (level == 0 ) {
556
- val evaluatedSplice = Splicer .splice(spliced, tree.pos, macroClassLoader).withPos(tree.pos)
557
- if (ctx.reporter.hasErrors) EmptyTree
558
- else transform(cpy.Inlined (tree)(call, bindings, evaluatedSplice))
559
- }
560
- else super .transform(tree)
561
-
562
- // due to value-discarding which converts an { e } into { e; () })
563
- if (tree.tpe =:= defn.UnitType ) Block (tree2 :: Nil , Literal (Constant (())))
564
- else tree2
582
+ case tree : Inlined if ! isInlined && level == 0 =>
583
+ inlined.transform(tree)
565
584
case _ : Import =>
566
585
tree
567
- case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
568
- markDef(tree)
569
- tree.rhs match {
570
- case InlineSplice (_) =>
571
- mapOverTree(enteredSyms) // Ignore output, only check PCP
572
- cpy.DefDef (tree)(rhs = defaultValue(tree.rhs.tpe))
573
- case _ =>
574
- ctx.error(
575
- """ Malformed inline macro.
576
- |
577
- |Expected the ~ to be at the top of the RHS:
578
- | inline def foo(x: X, ..., y: Y): Int = ~impl(x, ... '(y))
579
- |
580
- |The contents of the splice must call a static method. Arguments must be quoted or inlined.
581
- """ .stripMargin, tree.rhs.pos)
582
- EmptyTree
583
- }
584
586
case _ =>
585
587
markDef(tree)
586
588
checkLevel(mapOverTree(enteredSyms))
0 commit comments