-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Constructor proxy is restricted if class is protected #22563
Constructor proxy is restricted if class is protected #22563
Conversation
2388ac7
to
eecbac3
Compare
eecbac3
to
8c5f1f0
Compare
Silly how-I-fixed-it parody: How I fixed it: I searched github for something similar Prof Odersky had fixed, and I tried to copy that. I saw some bit flags, and since I miss coding in C, I thought I'd try that. It didn't work but threw an exception. It's way past midnight because I had an extra coffee this afternoon. I've already done the word puzzles for tomorrow. I said I better use the class symbol to check if it's protected, so I did that and the test passed, so that's when I stopped. The test is just the OP, plus a line to show something else that doesn't work and something else that does. Edit: just because it's a parody doesn't mean it's not true. The follow-up to add a pos test was not a quickie and took some time, per the next comment. I would have liked visibility ("instrumentation") into operations on symbols and trees, but lacking that, excellent naming in the code base was very helpful. |
Refresher that qualified protected does not mean access is granted to subclasses of the privateWIthin boundary symbol. The expectation is that this works:
Scala 2 has the same behavior. An alternative is to require the companion to have the same access modifiers (that is, also be protected for this use case). |
Require the constructor companion to be protected if the class is; or create it protected. Otherwise, create protected proxies.
8c5f1f0
to
fddab10
Compare
The ❌ is an unrelated server failure. |
} | ||
case _ => | ||
tryInsertApplyOrImplicit(tree, pt, locked): | ||
errorTree(tree, MethodDoesNotTakeParameters(tree)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This delta was due to a println. Philosophically, tryInsert
is the important part, and putting it right of the arrow makes it less visible, and unduly highlights errorTree
. The edit with new syntax is clearer.
Usual idiom where "thing to the right" is less important for understanding because it doesn't carry much information:
def f(x: X) = x match
case _: Y =>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Calling a constructor proxy should be at least as restricted as using
new
.Add
Protected
to a constructor companion if the class is protected.If the companion exists but is not protected, then make the constructor proxy protected.
Explicit
new
already errored for access.Fixes #22560