diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index c9c96635d7c1..d321c12b6b8d 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -54,30 +54,14 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( * - If inside of a macro definition, check the validity of the macro. */ protected def transformSplice(body: Tree, splice: Tree)(implicit ctx: Context): Tree = { - if (level >= 1) { - val body1 = transform(body)(spliceContext) - splice match { - case Apply(fun: TypeApply, _) if splice.isTerm => - // Type of the splice itsel must also be healed - // internal.Quoted.expr[F[T]](... T ...) --> internal.Quoted.expr[F[$t]](... T ...) - val tp = checkType(splice.sourcePos).apply(splice.tpe.widenTermRefExpr) - cpy.Apply(splice)(cpy.TypeApply(fun)(fun.fun, tpd.TypeTree(tp) :: Nil), body1 :: Nil) - case splice: Select => cpy.Select(splice)(body1, splice.name) - } - } - else { - assert(enclosingInlineds.isEmpty, "unexpanded macro") - assert(ctx.owner.isInlineMethod) - if (Splicer.canBeSpliced(body)) { // level 0 inside an inline definition - transform(body)(spliceContext) // Just check PCP - splice - } - else { // level 0 inside an inline definition - ctx.error( - "Malformed macro call. The contents of the splice ${...} must call a static method and arguments must be quoted or inline.", - splice.sourcePos) - splice - } + val body1 = transform(body)(spliceContext) + splice match { + case Apply(fun: TypeApply, _) if splice.isTerm => + // Type of the splice itsel must also be healed + // internal.Quoted.expr[F[T]](... T ...) --> internal.Quoted.expr[F[$t]](... T ...) + val tp = checkType(splice.sourcePos).apply(splice.tpe.widenTermRefExpr) + cpy.Apply(splice)(cpy.TypeApply(fun)(fun.fun, tpd.TypeTree(tp) :: Nil), body1 :: Nil) + case splice: Select => cpy.Select(splice)(body1, splice.name) } } diff --git a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala index 97ebf77b5fca..e74a2c3b3442 100644 --- a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala +++ b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala @@ -251,9 +251,14 @@ object PrepareInlineable { */ object InlineSplice { def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match { - case Spliced(code) if Splicer.canBeSpliced(code) => - if (code.symbol.flags.is(Inline)) + case Spliced(code) => + if (!Splicer.canBeSpliced(code)) { + ctx.error( + "Malformed macro call. The contents of the splice ${...} must call a static method and arguments must be quoted or inline.", + tree.sourcePos) + } else if (code.symbol.flags.is(Inline)) { ctx.error("Macro cannot be implemented with an `inline` method", code.sourcePos) + } Some(code) case Block(List(stat), Literal(Constants.Constant(()))) => unapply(stat) case Block(Nil, expr) => unapply(expr) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 807cda83bde1..4cdd973788ae 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2263,7 +2263,7 @@ class Typer extends Namer ctx.error("Splice ${...} outside quotes '{...} or inline method", tree.sourcePos) else if (level < 0) ctx.error( - """Splice ${...} at level -1. + s"""Splice $${...} at level $level. | |Inline method may contain a splice at level 0 but the contents of this splice cannot have a splice. |""".stripMargin, tree.sourcePos