@@ -222,39 +222,42 @@ object PrepareInlineable {
222
222
val inlineCtx = ctx
223
223
inlined.updateAnnotation(LazyBodyAnnotation { _ =>
224
224
implicit val ctx = inlineCtx
225
- val rawBody = treeExpr(ctx)
226
- val typedBody =
227
- if (ctx.reporter.hasErrors) rawBody
228
- else ctx.compilationUnit.inlineAccessors.makeInlineable(rawBody)
229
- checkInlineMethod(inlined, typedBody)
230
- val inlineableBody = typedBody
231
- inlining.println(i " Body to inline for $inlined: $inlineableBody" )
232
- inlineableBody
225
+ val initialErrorCount = ctx.reporter.errorCount
226
+ var inlinedBody = treeExpr(ctx)
227
+ if (ctx.reporter.errorCount == initialErrorCount) {
228
+ inlinedBody = ctx.compilationUnit.inlineAccessors.makeInlineable(inlinedBody)
229
+ checkInlineMethod(inlined, inlinedBody)
230
+ if (ctx.reporter.errorCount != initialErrorCount)
231
+ inlinedBody = EmptyTree
232
+ }
233
+ inlining.println(i " Body to inline for $inlined: $inlinedBody" )
234
+ inlinedBody
233
235
})
234
236
}
235
237
}
236
238
237
239
def checkInlineMethod (inlined : Symbol , body : Tree )(implicit ctx : Context ): Unit = {
240
+ if (inlined.owner.isClass && inlined.owner.seesOpaques)
241
+ ctx.error(em " Implementation restriction: No inline methods allowed where opaque type aliases are in scope " , inlined.sourcePos)
238
242
if (ctx.outer.inInlineMethod)
239
243
ctx.error(ex " implementation restriction: nested inline methods are not supported " , inlined.sourcePos)
240
244
if (inlined.name.isUnapplyName && tupleArgs(body).isEmpty)
241
245
ctx.warning(
242
246
em " inline unapply method can be rewritten only if its right hand side is a tuple (e1, ..., eN) " ,
243
247
body.sourcePos)
244
- }
248
+ if (inlined.is( Macro ) && ! ctx.isAfterTyper) {
245
249
246
- def checkInlineMacro (sym : Symbol , rhs : Tree , pos : SourcePosition )(implicit ctx : Context ) =
247
- if (sym.is(Macro ) && ! ctx.isAfterTyper) {
248
- def isValidMacro (tree : Tree )(implicit ctx : Context ): Unit = tree match {
250
+ def checkMacro (tree : Tree ): Unit = tree match {
249
251
case Spliced (code) =>
252
+ if (code.symbol.flags.is(Inline ))
253
+ ctx.error(" Macro cannot be implemented with an `inline` method" , code.sourcePos)
250
254
Splicer .checkValidMacroBody(code)
251
- new PCPCheckAndHeal (freshStagingContext).transform(rhs) // Ignore output, only check PCP
252
-
253
- case Block (List (stat), Literal (Constants .Constant (()))) => isValidMacro(stat)
254
- case Block (Nil , expr) => isValidMacro(expr)
255
- case Typed (expr, _) => isValidMacro(expr)
255
+ new PCPCheckAndHeal (freshStagingContext).transform(body) // Ignore output, only check PCP
256
+ case Block (List (stat), Literal (Constants .Constant (()))) => checkMacro(stat)
257
+ case Block (Nil , expr) => checkMacro(expr)
258
+ case Typed (expr, _) => checkMacro(expr)
256
259
case Block (DefDef (nme.ANON_FUN , _, _, _, _) :: Nil , Closure (_, fn, _)) if fn.symbol.info.isImplicitMethod =>
257
- // TODO Suppot this pattern
260
+ // TODO Support this pattern
258
261
ctx.error(
259
262
""" Macros using a return type of the form `foo(): given X => Y` are not yet supported.
260
263
|
@@ -269,9 +272,9 @@ object PrepareInlineable {
269
272
|
270
273
| * The contents of the splice must call a static method
271
274
| * All arguments must be quoted or inline
272
- """ .stripMargin, pos )
275
+ """ .stripMargin, inlined.sourcePos )
273
276
}
274
- isValidMacro(rhs )
277
+ checkMacro(body )
275
278
}
279
+ }
276
280
}
277
-
0 commit comments