Skip to content

Commit cb15a69

Browse files
committed
Perform full check that a the contents of a macro are valid in PrepareInlineable
Avoid check duplication
1 parent 0e5e541 commit cb15a69

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
5454
* - If inside of a macro definition, check the validity of the macro.
5555
*/
5656
protected def transformSplice(body: Tree, splice: Tree)(implicit ctx: Context): Tree = {
57-
if (level >= 1) {
57+
if (level < 0) {
58+
ctx.error(s"Splice at level $level is not allowed", splice.sourcePos)
59+
splice
60+
} else {
5861
val body1 = transform(body)(spliceContext)
5962
splice match {
6063
case Apply(fun: TypeApply, _) if splice.isTerm =>
@@ -65,20 +68,6 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
6568
case splice: Select => cpy.Select(splice)(body1, splice.name)
6669
}
6770
}
68-
else {
69-
assert(enclosingInlineds.isEmpty, "unexpanded macro")
70-
assert(ctx.owner.isInlineMethod)
71-
if (Splicer.canBeSpliced(body)) { // level 0 inside an inline definition
72-
transform(body)(spliceContext) // Just check PCP
73-
splice
74-
}
75-
else { // level 0 inside an inline definition
76-
ctx.error(
77-
"Malformed macro call. The contents of the splice ${...} must call a static method and arguments must be quoted or inline.",
78-
splice.sourcePos)
79-
splice
80-
}
81-
}
8271
}
8372

8473
/** If `tree` refers to a locally defined symbol (either directly, or in a pickled type),

compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,14 @@ object PrepareInlineable {
251251
*/
252252
object InlineSplice {
253253
def unapply(tree: Tree)(implicit ctx: Context): Option[Tree] = tree match {
254-
case Spliced(code) if Splicer.canBeSpliced(code) =>
255-
if (code.symbol.flags.is(Inline))
254+
case Spliced(code) =>
255+
if (!Splicer.canBeSpliced(code)) {
256+
ctx.error(
257+
"Malformed macro call. The contents of the splice ${...} must call a static method and arguments must be quoted or inline.",
258+
tree.sourcePos)
259+
} else if (code.symbol.flags.is(Inline)) {
256260
ctx.error("Macro cannot be implemented with an `inline` method", code.sourcePos)
261+
}
257262
Some(code)
258263
case Block(List(stat), Literal(Constants.Constant(()))) => unapply(stat)
259264
case Block(Nil, expr) => unapply(expr)

0 commit comments

Comments
 (0)