diff --git a/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala b/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala index b00552f9511c..e108d8c6cb8e 100644 --- a/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala +++ b/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala @@ -111,10 +111,13 @@ class Interpreter(implicit ctx: Context) { val env2 = bindings.foldLeft(env)((acc, x) => interpretStat(x, acc)) interpretTreeImpl(expansion, env2) + case Typed(expr, _) => + interpretTreeImpl(expr, env) + case _ => // TODO Add more precise descriptions of why it could not be interpreted. // This should be done after the full interpreter is implemented. - throw new StopInterpretation(s"Could not interpret ${tree.show}\n${tree}", tree.pos) + throw new StopInterpretation(s"Could not interpret ${tree.show}. Consider extracting logic into a helper def.", tree.pos) } } diff --git a/tests/run/quote-splice-interpret-1.check b/tests/run/quote-splice-interpret-1.check new file mode 100644 index 000000000000..d25232800f82 --- /dev/null +++ b/tests/run/quote-splice-interpret-1.check @@ -0,0 +1,2 @@ +true +false \ No newline at end of file diff --git a/tests/run/quote-splice-interpret-1/Macro_1.scala b/tests/run/quote-splice-interpret-1/Macro_1.scala new file mode 100644 index 000000000000..051c434a9a86 --- /dev/null +++ b/tests/run/quote-splice-interpret-1/Macro_1.scala @@ -0,0 +1,14 @@ +import dotty.tools.dotc.ast.Trees.Import + +import scala.quoted._ +object Macros { + sealed trait Nat + case object Z extends Nat + case class S[N <: Nat]() extends Nat + + inline def isZero(inline n: Int): Boolean = ~{ + if (n == 0) (true: Expr[Boolean]) + else (false: Expr[Boolean]) + } + +} diff --git a/tests/run/quote-splice-interpret-1/Test_2.scala b/tests/run/quote-splice-interpret-1/Test_2.scala new file mode 100644 index 000000000000..5a1b4b2b4c2a --- /dev/null +++ b/tests/run/quote-splice-interpret-1/Test_2.scala @@ -0,0 +1,7 @@ +import Macros._ +object Test { + def main(args: Array[String]): Unit = { + println(isZero(0)) + println(isZero(1)) + } +}