Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down