@@ -209,6 +209,17 @@ object PrepareInlineable {
209209 if original.mods.hasMod(classOf [untpd.Mod .Transparent ]) then rhs
210210 else Typed (rhs, tpt)
211211
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+
212223 /** Register inline info for given inlineable method `sym`.
213224 *
214225 * @param sym The symbol denotation of the inlineable method for which info is registered
@@ -227,21 +238,18 @@ object PrepareInlineable {
227238 val inlineCtx = ctx
228239 inlined.updateAnnotation(LazyBodyAnnotation {
229240 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)))
238246 inlining.println(i " Body to inline for $inlined: $inlinedBody" )
239247 inlinedBody
240248 })
241249 }
242250 }
243251
244- def checkInlineMethod (inlined : Symbol , body : Tree )(using Context ): Unit = {
252+ def checkInlineMethod (inlined : Symbol , body : Tree )(using Context ): body. type = {
245253 if (inlined.owner.isClass && inlined.owner.seesOpaques)
246254 ctx.error(em " Implementation restriction: No inline methods allowed where opaque type aliases are in scope " , inlined.sourcePos)
247255 if Inliner .inInlineMethod(using ctx.outer) then
@@ -278,5 +286,6 @@ object PrepareInlineable {
278286 }
279287 checkMacro(body)
280288 }
289+ body
281290 }
282291}
0 commit comments