Skip to content

Inlining private method breaks compilation #14042

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

Closed
scf37 opened this issue Dec 5, 2021 · 6 comments · Fixed by #15075
Closed

Inlining private method breaks compilation #14042

scf37 opened this issue Dec 5, 2021 · 6 comments · Fixed by #15075
Assignees
Milestone

Comments

@scf37
Copy link

scf37 commented Dec 5, 2021

Compiler version

3.1.0

Minimized code

trait T {
  inline def foo(handler: Int): Unit =
    bar(handler)

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

new T {
  foo(42)
}

Output

undefined: T_this.bar # -1: TermRef(TermRef(NoPrefix,val T_this),bar) at inlining

Expectation

Successful compilation

@scf37 scf37 added the itype:bug label Dec 5, 2021
@odersky
Copy link
Contributor

odersky commented Dec 5, 2021

It's because we do not generate inline accessors for inline methods. See needsAccessor in PrepareInlineable.

I see two possible ways to fix this. Ideally, we do create an inline accessor which is itself defined
inline (and transparent, if the accessed method is transparent). I tried that, but it does not work currently, since the inline accessor does not get inlined.

If that does not work, we could also issue a static error if an inline method calls a private inline method.

@odersky
Copy link
Contributor

odersky commented Dec 5, 2021

It turns out the static error route would invalidate several existing tests and the compiler itself.

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Dec 6, 2021

To fix this we first need to fix #14048 as we would probably fit it on the way.

@nicolasstucki
Copy link
Contributor

We should be evaluating this branch but the symbol is NoSymbol.
https://github.com/lampepfl/dotty/blob/main/compiler/src/dotty/tools/dotc/typer/Inliner.scala#L1584

@nicolasstucki
Copy link
Contributor

The issue comes from transforming new T { foo(42) } into new T { bar(42) }. As bar is private in T it cannot be selected from the anonymous new T.

@odersky is there a way to compute this symbol?

@odersky
Copy link
Contributor

odersky commented Apr 13, 2022

@nicolasstucki Not if it is private.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants