diff --git a/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala b/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala index 5be936d71ee1..0218f7f8b481 100644 --- a/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala +++ b/compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala @@ -63,17 +63,13 @@ class Interpreter(implicit ctx: Context) { * If some error is encountered while interpreting a ctx.error is emitted and a StopInterpretation is thrown. */ private def interpretTreeImpl(tree: Tree, env: Env): Object = { - ctx.debuglog( - s"""Interpreting: - |${tree.show} - |$env - """.stripMargin) + // println(s"Interpreting:\n${tree.show}\n$env\n") implicit val pos: Position = tree.pos tree match { case Quoted(quotedTree) => - if (tree.isTerm) new scala.quoted.Exprs.TreeExpr(quotedTree) + if (quotedTree.isTerm) new scala.quoted.Exprs.TreeExpr(quotedTree) else new scala.quoted.Types.TreeType(quotedTree) case Literal(Constant(c)) => c.asInstanceOf[Object] @@ -114,6 +110,9 @@ class Interpreter(implicit ctx: Context) { val env2 = bindings.foldLeft(env)((acc, x) => interpretStat(x, acc)) interpretTreeImpl(expansion, env2) + case TypeApply(fn, _) => + interpretTreeImpl(fn, env) + case Typed(expr, _) => interpretTreeImpl(expr, env) diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 163c3db800b0..adaec52a2917 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -77,6 +77,7 @@ class ReifyQuotes extends MacroTransformWithImplicits { */ private class Reifier(inQuote: Boolean, val outer: Reifier, val level: Int, levels: LevelInfo) extends ImplicitsTransformer { import levels._ + assert(level >= 0) /** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */ def nested(isQuote: Boolean): Reifier = @@ -160,17 +161,22 @@ class ReifyQuotes extends MacroTransformWithImplicits { */ def tryHeal(tp: Type, pos: Position)(implicit ctx: Context): Option[String] = tp match { case tp: TypeRef => - val reqType = defn.QuotedTypeType.appliedTo(tp) - val tag = ctx.typer.inferImplicitArg(reqType, pos) - tag.tpe match { - case fail: SearchFailureType => - Some(i""" - | - | The access would be accepted with the right type tag, but - | ${ctx.typer.missingArgMsg(tag, reqType, "")}""") - case _ => - importedTags(tp) = nested(isQuote = false).transform(tag) - None + if (level == 0) { + assert(ctx.owner.is(Macro)) + None + } else { + val reqType = defn.QuotedTypeType.appliedTo(tp) + val tag = ctx.typer.inferImplicitArg(reqType, pos) + tag.tpe match { + case fail: SearchFailureType => + Some(i""" + | + | The access would be accepted with the right type tag, but + | ${ctx.typer.missingArgMsg(tag, reqType, "")}""") + case _ => + importedTags(tp) = nested(isQuote = false).transform(tag) + None + } } case _ => Some("") diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 2003dba73999..1e71ce697d85 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -16,10 +16,7 @@ object Splicer { */ def splice(tree: Tree)(implicit ctx: Context): Tree = tree match { case Quoted(quotedTree) => quotedTree - case tree: RefTree => reflectiveSplice(tree) - case tree: Apply => reflectiveSplice(tree) - case tree: Inlined => reflectiveSplice(tree) - case tree: Block => reflectiveSplice(tree) + case _ => reflectiveSplice(tree) } /** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */ diff --git a/tests/pos/i4023/Macro_1.scala b/tests/pos/i4023/Macro_1.scala new file mode 100644 index 000000000000..c3c0d2100e14 --- /dev/null +++ b/tests/pos/i4023/Macro_1.scala @@ -0,0 +1,5 @@ +import scala.quoted._ +object Macro { + inline def ff[T: Type](x: T): T = ~impl('(x)) + def impl[T](x: Expr[T]): Expr[T] = x +} \ No newline at end of file diff --git a/tests/pos/i4023/Test_2.scala b/tests/pos/i4023/Test_2.scala new file mode 100644 index 000000000000..73250b37c2c1 --- /dev/null +++ b/tests/pos/i4023/Test_2.scala @@ -0,0 +1,3 @@ +object Test { + Macro.ff(3) +} diff --git a/tests/pos/i4023b/Macro_1.scala b/tests/pos/i4023b/Macro_1.scala new file mode 100644 index 000000000000..7aa305e3183a --- /dev/null +++ b/tests/pos/i4023b/Macro_1.scala @@ -0,0 +1,5 @@ +import scala.quoted._ +object Macro { + inline def ff[T](implicit t: Type[T]): Int = ~impl[T] + def impl[T]: Expr[Int] = 4 +} diff --git a/tests/pos/i4023b/Test_2.scala b/tests/pos/i4023b/Test_2.scala new file mode 100644 index 000000000000..4bd71c799fbf --- /dev/null +++ b/tests/pos/i4023b/Test_2.scala @@ -0,0 +1,3 @@ +object Test { + Macro.ff[Int] +} diff --git a/tests/pos/i4023c/Macro_1.scala b/tests/pos/i4023c/Macro_1.scala new file mode 100644 index 000000000000..7e5714514b8d --- /dev/null +++ b/tests/pos/i4023c/Macro_1.scala @@ -0,0 +1,5 @@ +import scala.quoted._ +object Macro { + inline def ff[T](x: T): T = ~impl('(x), '[T]) + def impl[T](x: Expr[T], t: Type[T]): Expr[T] = '{ (~x): ~t } +} diff --git a/tests/pos/i4023c/Test_2.scala b/tests/pos/i4023c/Test_2.scala new file mode 100644 index 000000000000..512a2ab27495 --- /dev/null +++ b/tests/pos/i4023c/Test_2.scala @@ -0,0 +1,7 @@ +object Test { + Macro.ff(3) + + def f[T](x: T) = { + Macro.ff(x) + } +} diff --git a/tests/pos/macro-with-type/Macro_1.scala b/tests/pos/macro-with-type/Macro_1.scala new file mode 100644 index 000000000000..5bf5885b3aa1 --- /dev/null +++ b/tests/pos/macro-with-type/Macro_1.scala @@ -0,0 +1,5 @@ +import scala.quoted._ +object Macro { + inline def ff: Unit = ~impl('[Int]) + def impl(t: Type[Int]): Expr[Unit] = () +} \ No newline at end of file diff --git a/tests/pos/macro-with-type/Test_2.scala b/tests/pos/macro-with-type/Test_2.scala new file mode 100644 index 000000000000..1c6c9b1b8201 --- /dev/null +++ b/tests/pos/macro-with-type/Test_2.scala @@ -0,0 +1,3 @@ +object Test { + Macro.ff +}