-
Notifications
You must be signed in to change notification settings - Fork 1.1k
private
-ness of trait constructor ignored
#17089
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
Comments
Error as expected with parameters. |
@som-snytt Yes, that's the point here. We don't call the constructor of a trait unless we have to pass parameters. So declaring it as |
Makes sense that the constructor is not called if there are no parameters to pass. But this sounds more like an optimization that should not affect the surface language. I find it a bit concerning that If the code is legal, Also, the statements in the trait's body are executed during construction (either as part of the constructor or of some special mixin initialization method). I think a reasonable expectation is that |
I agree this warrants further investigation. |
This allows to restrict inheritance of traits even if the constructor is not called, or not called at Typer. Fixes scala#17089
This allows to restrict inheritance of traits even if the constructor is not called, or not called at Typer. Fixes scala#17089
Compiler version
3.3.0-RC3
Minimized code
Output
The code compiles. I would expect it not to. My expectation was that
trait T private[o]()
scopes the constructor ofT
private ino
(but maybe this is not the case?). I assume that the anonymous class created innew o.T { }
calls theT
's constructor. If that is the case, then I think creating instances ofT
should only be possible withino
(which was the intention here).The text was updated successfully, but these errors were encountered: