Skip to content

Commit 8560bcc

Browse files
committed
Insert Splicer in ReifyQuote
1 parent 6a3bdb7 commit 8560bcc

File tree

6 files changed

+13
-4
lines changed

6 files changed

+13
-4
lines changed

compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.tpd
55
import dotty.tools.dotc.ast.Trees._
66
import dotty.tools.dotc.core.Constants._
77
import dotty.tools.dotc.core.Contexts._
8+
import dotty.tools.dotc.core.Flags._
89
import dotty.tools.dotc.core.Decorators._
910
import dotty.tools.dotc.core.Symbols._
1011

@@ -79,6 +80,12 @@ class Interpreter(implicit ctx: Context) {
7980
val method = clazz.getMethod(tree.name.toString)
8081
method.invoke(null)
8182

83+
case tree: RefTree if tree.symbol.is(Module) =>
84+
??? // TODO
85+
86+
case Inlined(_, bindings, expansion) =>
87+
// TODO evaluate bindings and add environment
88+
interpretTreeImpl(expansion)
8289
case _ =>
8390
val msg =
8491
if (tree.tpe.derivesFrom(defn.QuotedExprClass)) "Quote needs to be explicit or a call to a static method"

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ class ReifyQuotes extends MacroTransform {
328328
case Inlined(call, bindings, expansion @ Select(body, name)) if expansion.symbol.isSplice =>
329329
// To maintain phase consistency, convert inlined expressions of the form
330330
// `{ bindings; ~expansion }` to `~{ bindings; expansion }`
331-
transform(cpy.Select(expansion)(cpy.Inlined(tree)(call, bindings, body), name))
331+
if (level == 0) transform(Splicer.splice(cpy.Inlined(tree)(call, bindings, body)))
332+
else transform(cpy.Select(expansion)(cpy.Inlined(tree)(call, bindings, body), name))
332333
case _: Import =>
333334
tree
334335
case tree: DefDef if tree.symbol.is(Macro) && level == 0 =>

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Splicer {
2222
case TypeApply(quote, quoted :: Nil) if quote.symbol == defn.typeQuoteMethod => quoted
2323
case tree: RefTree => reflectiveSplice(tree)
2424
case tree: Apply => reflectiveSplice(tree)
25-
case Inlined(_, _, expansion) => splice(expansion)
25+
case tree: Inlined => reflectiveSplice(tree)
2626
}
2727

2828
/** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10741074
}
10751075

10761076
def typedQuote(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = track("typedQuote") {
1077+
ctx.compilationUnit.containsQuotesOrSplices = true
10771078
val untpd.Quote(body) = tree
10781079
val isType = body.isType
10791080
val resultClass = if (isType) defn.QuotedTypeClass else defn.QuotedExprClass

tests/run/quote-and-splice.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3

tests/run/quote-and-splice/Test_2.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ object Test {
22
import Macros._
33

44
def main(args: Array[String]): Unit = {
5-
// FIXME
6-
// println(macro1)
5+
println(macro1)
76
}
87

98
}

0 commit comments

Comments
 (0)