Skip to content

inline methods can leak references to private classes #8194

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

Open
LPTK opened this issue Feb 4, 2020 · 1 comment
Open

inline methods can leak references to private classes #8194

LPTK opened this issue Feb 4, 2020 · 1 comment
Labels
area:inline area:reporting Error reporting including formatting, implicit suggestions, etc backlog No work planned on this by the core team for the time being. exp:advanced help wanted itype:enhancement

Comments

@LPTK
Copy link
Contributor

LPTK commented Feb 4, 2020

minimized code

object Test {
  private class A() { def test = 42 }
  inline def foo: Int = A().test
}
@main def main = Test.foo

https://scastie.scala-lang.org/or0Eg6u9Tky1ImaUNEdOug

Compilation output

class A in object Test cannot be accessed as a member of (Test : Test.type) from module class main$package$.

expectation

This should compile, or at least report an error at the definition site of the inline method (similarly to how errors are reported when classes leak private val references), not at call sites.

@odersky
Copy link
Contributor

odersky commented Feb 5, 2020

The fine print of this is actually very tricky. The problem in general is that an inline method could be called in a contect where a type it refers to is not accessible. This looks very hard to implement without getting false negatives. Even the limited case of just flagging accesses to private types looks non-trivial. It requires a complete refactoring of the code in checkNoPrivateLeaks which itself is quite tricky. So, this will be time consuming to do, and the benefits are not that great. I think this is a case where outside contributions would be welcome and not much will happen without them.

@odersky odersky added area:inline area:reporting Error reporting including formatting, implicit suggestions, etc exp:advanced help wanted labels Feb 5, 2020
@odersky odersky added the backlog No work planned on this by the core team for the time being. label Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:inline area:reporting Error reporting including formatting, implicit suggestions, etc backlog No work planned on this by the core team for the time being. exp:advanced help wanted itype:enhancement
Projects
None yet
Development

No branches or pull requests

3 participants