Skip to content

Commit

Permalink
Merge pull request #14049 from dotty-staging/fix-#14048
Browse files Browse the repository at this point in the history
Inline inlined private methods before checking accessibility
  • Loading branch information
odersky committed Dec 10, 2021
2 parents 9913ee6 + 5c056b3 commit 33ab1b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1548,13 +1548,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
//if the projection leads to a typed tree then we stop reduction
resNoReduce
else
val resMaybeReduced = constToLiteral(reducedProjection)
if resNoReduce ne resMaybeReduced then
typed(resMaybeReduced, pt) // redo typecheck if reduction changed something
val res = constToLiteral(reducedProjection)
if resNoReduce ne res then
typed(res, pt) // redo typecheck if reduction changed something
else if res.symbol.isInlineMethod then
inlineIfNeeded(res)
else
val res = resMaybeReduced
ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.srcPos)
inlineIfNeeded(res)
res
}

override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree =
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i14048.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class T:
inline def foo(): Unit = bar()
private inline def bar(): Unit = ()

def test(t: T) = t.foo()

0 comments on commit 33ab1b2

Please sign in to comment.