Skip to content

Commit 33ab1b2

Browse files
authored
Merge pull request #14049 from dotty-staging/fix-#14048
Inline inlined private methods before checking accessibility
2 parents 9913ee6 + 5c056b3 commit 33ab1b2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,13 +1548,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
15481548
//if the projection leads to a typed tree then we stop reduction
15491549
resNoReduce
15501550
else
1551-
val resMaybeReduced = constToLiteral(reducedProjection)
1552-
if resNoReduce ne resMaybeReduced then
1553-
typed(resMaybeReduced, pt) // redo typecheck if reduction changed something
1551+
val res = constToLiteral(reducedProjection)
1552+
if resNoReduce ne res then
1553+
typed(res, pt) // redo typecheck if reduction changed something
1554+
else if res.symbol.isInlineMethod then
1555+
inlineIfNeeded(res)
15541556
else
1555-
val res = resMaybeReduced
15561557
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos)
1557-
inlineIfNeeded(res)
1558+
res
15581559
}
15591560

15601561
override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree =

tests/pos/i14048.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class T:
2+
inline def foo(): Unit = bar()
3+
private inline def bar(): Unit = ()
4+
5+
def test(t: T) = t.foo()

0 commit comments

Comments
 (0)