@@ -245,51 +245,36 @@ object PrepareInlineable {
245
245
}
246
246
247
247
def checkInlineMacro (sym : Symbol , rhs : Tree , pos : SourcePosition )(implicit ctx : Context ) = {
248
- if (! ctx.isAfterTyper) {
249
- var isMacro = false
250
- new TreeMapWithStages (freshStagingContext) {
251
- override protected def transformSplice (body : tpd.Tree , splice : tpd.Tree )(implicit ctx : Context ): tpd.Tree = {
252
- isMacro = true
253
- splice
254
- }
255
- override def transform (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree =
256
- if (isMacro) tree else super .transform(tree)
257
- }.transform(rhs)
258
-
259
- if (isMacro) {
260
- sym.setFlag(Macro )
261
- if (level == 0 ) {
262
- def isValidMacro (tree : Tree )(implicit ctx : Context ): Unit = tree match {
263
- case Spliced (code) =>
264
- if (code.symbol.flags.is(Inline ))
265
- ctx.error(" Macro cannot be implemented with an `inline` method" , code.sourcePos)
266
- Splicer .checkValidMacroBody(code)
267
- new PCPCheckAndHeal (freshStagingContext).transform(rhs) // Ignore output, only check PCP
248
+ if (sym.is(Macro ) && ! ctx.isAfterTyper) {
249
+ def isValidMacro (tree : Tree )(implicit ctx : Context ): Unit = tree match {
250
+ case Spliced (code) =>
251
+ if (code.symbol.flags.is(Inline ))
252
+ ctx.error(" Macro cannot be implemented with an `inline` method" , code.sourcePos)
253
+ Splicer .checkValidMacroBody(code)
254
+ new PCPCheckAndHeal (freshStagingContext).transform(rhs) // Ignore output, only check PCP
268
255
269
- case Block (List (stat), Literal (Constants .Constant (()))) => isValidMacro(stat)
270
- case Block (Nil , expr) => isValidMacro(expr)
271
- case Typed (expr, _) => isValidMacro(expr)
272
- case Block (DefDef (nme.ANON_FUN , _, _, _, _) :: Nil , Closure (_, fn, _)) if fn.symbol.info.isImplicitMethod =>
273
- // TODO Suppot this pattern
274
- ctx.error(
275
- """ Macros using a return type of the form `foo(): given X => Y` are not yet supported.
276
- |
277
- |Place the implicit as an argument (`foo() given X: Y`) to overcome this limitation.
278
- |""" .stripMargin, tree.sourcePos)
279
- case _ =>
280
- ctx.error(
281
- """ Malformed macro.
282
- |
283
- |Expected the splice ${...} to be at the top of the RHS:
284
- | inline def foo(inline x: X, ..., y: Y): Int = ${impl(x, ... '{y}})
285
- |
286
- | * The contents of the splice must call a static method
287
- | * All arguments must be quoted or inline
288
- """ .stripMargin, pos)
289
- }
290
- isValidMacro(rhs)
291
- }
256
+ case Block (List (stat), Literal (Constants .Constant (()))) => isValidMacro(stat)
257
+ case Block (Nil , expr) => isValidMacro(expr)
258
+ case Typed (expr, _) => isValidMacro(expr)
259
+ case Block (DefDef (nme.ANON_FUN , _, _, _, _) :: Nil , Closure (_, fn, _)) if fn.symbol.info.isImplicitMethod =>
260
+ // TODO Suppot this pattern
261
+ ctx.error(
262
+ """ Macros using a return type of the form `foo(): given X => Y` are not yet supported.
263
+ |
264
+ |Place the implicit as an argument (`foo() given X: Y`) to overcome this limitation.
265
+ |""" .stripMargin, tree.sourcePos)
266
+ case _ =>
267
+ ctx.error(
268
+ """ Malformed macro.
269
+ |
270
+ |Expected the splice ${...} to be at the top of the RHS:
271
+ | inline def foo(inline x: X, ..., y: Y): Int = ${impl(x, ... '{y}})
272
+ |
273
+ | * The contents of the splice must call a static method
274
+ | * All arguments must be quoted or inline
275
+ """ .stripMargin, pos)
292
276
}
277
+ isValidMacro(rhs)
293
278
}
294
279
}
295
280
0 commit comments