Skip to content

Commit c245e66

Browse files
committed
Support inline methods calling private inline methods on this
Fix #14042
1 parent 400427d commit c245e66

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
995995
inlinedFromOutside(TypeTree(t).withSpan(argSpan))(tree.span)
996996
case _ => tree
997997
}
998+
case tree @ Select(qual: This, name) if tree.symbol.is(Private) && tree.symbol.isInlineMethod =>
999+
// This inline method refers to another (private) inline method (see tests/pos/i14042.scala).
1000+
// We insert upcast to access the private inline method once inlined. This makes the selection
1001+
// keep the symbol when re-typechecking in the InlineTyper. The method is inlined and hence no
1002+
// reference to a private method is kept at runtime.
1003+
cpy.Select(tree)(qual.asInstance(qual.tpe.widen), name)
1004+
9981005
case tree => tree
9991006
},
10001007
oldOwners = inlinedMethod :: Nil,

tests/pos/i14042.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait T {
2+
inline def foo(handler: Int): Unit =
3+
bar(handler)
4+
5+
private inline def bar(handler: Int): Unit = ()
6+
}
7+
8+
def test = new T {
9+
foo(42)
10+
this.foo(42)
11+
def test = this.foo(42)
12+
}
13+
14+
def test2(t: T) =
15+
t.foo(42)

0 commit comments

Comments
 (0)