Skip to content

Commit 3f8702b

Browse files
committed
Insert Splicer in ReifyQuote
1 parent 40f9a15 commit 3f8702b

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
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-
cpy.Select(expansion)(cpy.Inlined(tree)(call, bindings, body), name)
331+
if (level == 0) Splicer.splice(cpy.Inlined(tree)(call, bindings, body))
332+
else 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 */

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

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

44
def main(args: Array[String]): Unit = {
5-
try {
6-
println(macro1)
7-
} catch {
8-
case _: Error => // FIXME remove try/catch
9-
println(3)
10-
}
5+
println(macro1)
116
}
127

138
}

0 commit comments

Comments
 (0)