Skip to content

Support inline methods calling private inline methods on this #15075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)