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
check private[this] members in override checking #9542
Conversation
OK, I agree that if there are matching members, the "bottom" member (and here one may need terminology from urban dictionary) cannot constrain the visibility. The spec says you inherit one member and the other is defined directly, which may have an arbitrary modifier. That is, on the "high" or "top" side, a private member should not mess with me. But from my perspective, I must understand and contend with any inherited members. |
Reading through the spec, I cannot see anything that makes https://www.scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html#private
https://www.scala-lang.org/files/archive/spec/2.13/05-classes-and-objects.html#class-members
So a |
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.
Took me a minute to mentally verify the intuition and the implementation and then also try it out.
@lrytz I remember this came up at team meeting yesterday but I don't recall if any new conclusions were reached...? |
I was trying to recall when visibility came to figure into inheritability; I thought Paul's thing was that you should be able to add a private or private[enough] member without worrying about conflicts. I remember he tweaked it without a SIP, but I didn't have time to time to consult the history. That's why I was skeptical; but I also think that in the face of brittle inheritance, you're not allowed to be ignorant of or isolated from your base classes or subclasses. |
Not really, I think the next step is community build; we could merge this and revert if necessary. |
OK, I was thinking of imports not inheritance. "Importable" changed from "not private[this]" to "accessible". I'm sure glad I cleared that up; I wouldn't have slept for a week. |
OK, merged and let's see. |
I'll run the community build soon (this week) and see if something squawks. |
@lrytz the community build found the following needed changes; do they seem expected to you? |
These look expected to me. Do you think the error message is good enough? |
Well... it's not great. stab at a better one: "an override cannot have more restricted access than the method it overrides; method |
That's a good point. "Weaker access privilege" is what people are in the streets protesting about. As a security concept, privilege as in privileged code implies an authorization that can be acquired or not; but maybe we're too comfortable with The other part of the message is that if the user did not write Is it too annoying:
|
Previously,
private[this]
members were not considered in override checking, so a subclass could have aprivate[this]
memberx
while also inheriting a memberx
, which leads to anIllegalAccessError
at runtimeWith this PR, the
private[this]
"overrides" are rejected ("error: weaker access privileges in overriding")Fixes scala/bug#9334