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
Private constructors and methods are compiled to public visibility when accessed from a companion object #6882
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6882?orig=1 |
Paul Lysak (paul.lysak) said: |
@SethTisue said: |
@SethTisue said: |
See #7085 for more details on the idea of adding a synthetic static accessor. Which I think should work for a private constructor. |
Oh see also #7085 (comment):
|
Private constructors and methods are compiled to public visibility when a companion object access them. This should arguably be the "most private" possible. While the Scala compiler should (and likely does, I didn't test it) enforce the visibility restrictions, when interoperating with Java, it would be preferable to have something other than public visibility here.
Per Simon Ochsenreither, the issue could be solvable by emitting an appropriate static forwarder in the class.
Example with expected results (no companion object):
javap -p output with private constructor and method:
This is expected.
However, adding the companion object as follows results in the private constructor and method being generated as public.
javap -p output with public constructor and method:
The text was updated successfully, but these errors were encountered: