Skip to content

Commit e20904a

Browse files
committed
Fix problem affecting recursive inlines
The previous check whether a method was an inlined method with a body forced computation of the body, which led to problems when dealing with recursive inline methods.
1 parent e4427db commit e20904a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ object Inliner {
3737
def attachBody(inlineAnnot: Annotation, tree: => Tree)(implicit ctx: Context): Unit =
3838
inlineAnnot.tree.putAttachment(InlinedBody, new InlinedBody(tree))
3939

40-
def inlinedBody(sym: SymDenotation)(implicit ctx: Context): Option[Tree] =
41-
sym.getAnnotation(defn.InlineAnnot).get.tree
42-
.getAttachment(InlinedBody).map(_.body)
40+
private def inlinedBodyAttachment(sym: SymDenotation)(implicit ctx: Context): Option[InlinedBody] =
41+
sym.getAnnotation(defn.InlineAnnot).get.tree.getAttachment(InlinedBody)
42+
43+
def hasInlinedBody(sym: SymDenotation)(implicit ctx: Context): Boolean =
44+
inlinedBodyAttachment(sym).isDefined
45+
46+
def inlinedBody(sym: SymDenotation)(implicit ctx: Context): Tree =
47+
inlinedBodyAttachment(sym).get.body
4348

4449
def inlineCall(tree: Tree, pt: Type)(implicit ctx: Context): Tree =
4550
if (enclosingInlineds.length < ctx.settings.xmaxInlines.value)
46-
new Inliner(tree, inlinedBody(tree.symbol).get).inlined(pt)
51+
new Inliner(tree, inlinedBody(tree.symbol)).inlined(pt)
4752
else errorTree(tree,
4853
i"""Maximal number of successive inlines (${ctx.settings.xmaxInlines.value}) exceeded,
4954
| Maybe this is caused by a recursive inline method?

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
17571757
}
17581758
else if (tree.tpe <:< pt)
17591759
if (tree.symbol.isInlineMethod &&
1760-
Inliner.inlinedBody(tree.symbol).isDefined &&
1760+
Inliner.hasInlinedBody(tree.symbol) &&
17611761
!ctx.owner.ownersIterator.exists(_.isInlineMethod) &&
17621762
!ctx.settings.YnoInline.value &&
17631763
!ctx.isAfterTyper)

0 commit comments

Comments
 (0)