@@ -209,6 +209,17 @@ object PrepareInlineable {
209
209
if original.mods.hasMod(classOf [untpd.Mod .Transparent ]) then rhs
210
210
else Typed (rhs, tpt)
211
211
212
+ /** Return result of evaluating `op`, but drop `Inline` flag and `Body` annotation
213
+ * of `sym` in case that leads to errors.
214
+ */
215
+ def dropInlineIfError (sym : Symbol , op : => Tree )(using Context ): Tree =
216
+ val initialErrorCount = ctx.reporter.errorCount
217
+ try op
218
+ finally
219
+ if ctx.reporter.errorCount != initialErrorCount then
220
+ sym.resetFlag(Inline )
221
+ sym.removeAnnotation(defn.BodyAnnot )
222
+
212
223
/** Register inline info for given inlineable method `sym`.
213
224
*
214
225
* @param sym The symbol denotation of the inlineable method for which info is registered
@@ -227,21 +238,18 @@ object PrepareInlineable {
227
238
val inlineCtx = ctx
228
239
inlined.updateAnnotation(LazyBodyAnnotation {
229
240
given ctx as Context = inlineCtx
230
- val initialErrorCount = ctx.reporter.errorCount
231
- var inlinedBody = treeExpr
232
- if (ctx.reporter.errorCount == initialErrorCount) {
233
- inlinedBody = ctx.compilationUnit.inlineAccessors.makeInlineable(inlinedBody)
234
- checkInlineMethod(inlined, inlinedBody)
235
- if (ctx.reporter.errorCount != initialErrorCount)
236
- inlinedBody = EmptyTree
237
- }
241
+ var inlinedBody = dropInlineIfError(inlined, treeExpr)
242
+ if inlined.isInlineMethod then
243
+ inlinedBody = dropInlineIfError(inlined,
244
+ checkInlineMethod(inlined,
245
+ ctx.compilationUnit.inlineAccessors.makeInlineable(inlinedBody)))
238
246
inlining.println(i " Body to inline for $inlined: $inlinedBody" )
239
247
inlinedBody
240
248
})
241
249
}
242
250
}
243
251
244
- def checkInlineMethod (inlined : Symbol , body : Tree )(using Context ): Unit = {
252
+ def checkInlineMethod (inlined : Symbol , body : Tree )(using Context ): body. type = {
245
253
if (inlined.owner.isClass && inlined.owner.seesOpaques)
246
254
ctx.error(em " Implementation restriction: No inline methods allowed where opaque type aliases are in scope " , inlined.sourcePos)
247
255
if Inliner .inInlineMethod(using ctx.outer) then
@@ -278,5 +286,6 @@ object PrepareInlineable {
278
286
}
279
287
checkMacro(body)
280
288
}
289
+ body
281
290
}
282
291
}
0 commit comments