Skip to content

Commit

Permalink
Merge pull request #15075 from dotty-staging/fix-14042
Browse files Browse the repository at this point in the history
Support inline methods calling private inline methods on `this`
  • Loading branch information
odersky authored May 6, 2022
2 parents 9865ef6 + c245e66 commit 86bb972
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
inlinedFromOutside(TypeTree(t).withSpan(argSpan))(tree.span)
case _ => tree
}
case tree @ Select(qual: This, name) if tree.symbol.is(Private) && tree.symbol.isInlineMethod =>
// This inline method refers to another (private) inline method (see tests/pos/i14042.scala).
// We insert upcast to access the private inline method once inlined. This makes the selection
// keep the symbol when re-typechecking in the InlineTyper. The method is inlined and hence no
// reference to a private method is kept at runtime.
cpy.Select(tree)(qual.asInstance(qual.tpe.widen), name)

case tree => tree
},
oldOwners = inlinedMethod :: Nil,
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i14042.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
trait T {
inline def foo(handler: Int): Unit =
bar(handler)

private inline def bar(handler: Int): Unit = ()
}

def test = new T {
foo(42)
this.foo(42)
def test = this.foo(42)
}

def test2(t: T) =
t.foo(42)

0 comments on commit 86bb972

Please # to comment.