File tree Expand file tree Collapse file tree 2 files changed +11
-17
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +11
-17
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
54
54
* - If inside of a macro definition, check the validity of the macro.
55
55
*/
56
56
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 {
58
61
val body1 = transform(body)(spliceContext)
59
62
splice match {
60
63
case Apply (fun : TypeApply , _) if splice.isTerm =>
@@ -65,20 +68,6 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
65
68
case splice : Select => cpy.Select (splice)(body1, splice.name)
66
69
}
67
70
}
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
- }
82
71
}
83
72
84
73
/** If `tree` refers to a locally defined symbol (either directly, or in a pickled type),
Original file line number Diff line number Diff line change @@ -251,9 +251,14 @@ object PrepareInlineable {
251
251
*/
252
252
object InlineSplice {
253
253
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 )) {
256
260
ctx.error(" Macro cannot be implemented with an `inline` method" , code.sourcePos)
261
+ }
257
262
Some (code)
258
263
case Block (List (stat), Literal (Constants .Constant (()))) => unapply(stat)
259
264
case Block (Nil , expr) => unapply(expr)
You can’t perform that action at this time.
0 commit comments