Skip to content
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

Add clause for protected visibility from package objects #18134

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jul 4, 2023

We usually have an access rule that the access to a protected member foo in class C
must be from somewhere nested in a subclass of C. But that fails if the member is
accessed from a package object p.package. In that case, the access does not need to be in
the same object, it just has to be in package p. This clause was previously missing
and is now added.

Why was this only recently discovered?

#18057 fixed an issue where toplevel protected members were always accessible
because explicit package object prefixes were added after the accessibility check was done,
and would re-establish the previous members without doing an accessibility check. The fix was
done by adding package objects first, then doing he rest of the checks. But that also means
that protected toplevel objects now get checked as members of their synthetic package object
instead of as members of their package.

The change here also makes specs2 compile again.

@odersky
Copy link
Contributor Author

odersky commented Jul 4, 2023

Fixes #18124

We usually have an access rule that the access to a protected member `foo` in class `C`
must be from somewhere nested in a subclass of `C`. But that fails if the member is
accessed from a package object `p.package`. In that case, the access does not need to be in
the same object, it just has to be in package `p`. This clause was previously missing
and is now added.

Why was this only recently discovered?

scala#18057 fixed an issue where toplevel protected members were always accessible
because explicit package object prefixes were added after the accessibility check was done,
and would re-establish the previous members without doing an accessibility check. The fix was
done by adding package objects first, then doing he rest of the checks. But that also means
that protected toplevel objects now get checked as members of their synthetic package object
instead of as members of their package.

The change here also makes specs2 compile again.
@odersky
Copy link
Contributor Author

odersky commented Jul 5, 2023

@Kordyjan This fixes a problem with the recently backported #18057 which caused a regression. So ideally it should land in the same release.

@odersky odersky added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Jul 5, 2023
@odersky odersky changed the title Make toplevel protected qualified protected @odersky Add clause for protected visibility from package objects Jul 5, 2023
@odersky odersky changed the title @odersky Add clause for protected visibility from package objects Add clause for protected visibility from package objects Jul 5, 2023
@Kordyjan
Copy link
Contributor

Kordyjan commented Jul 5, 2023

I will release RC3 as soon as this pr is merged then.

@odersky odersky merged commit c3445ac into scala:main Jul 5, 2023
@odersky odersky deleted the fix-18124 branch July 5, 2023 09:57
@Kordyjan Kordyjan mentioned this pull request Jul 5, 2023
13 tasks
@Kordyjan Kordyjan added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels Jul 5, 2023
@Kordyjan Kordyjan added this to the 3.3.1 milestone Jul 5, 2023
@Kordyjan Kordyjan modified the milestones: 3.3.1, 3.4.0 Aug 1, 2023
@Kordyjan Kordyjan added backport:done This PR was successfully backported. and removed backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels Aug 2, 2023
@Kordyjan Kordyjan modified the milestones: 3.4.0, 3.3.1 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:done This PR was successfully backported.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Protected top-level definition can no longer be referenced in other file
3 participants