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

Fix accessibleType for package object prefixes #18057

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 25, 2023

Making a package object explicit re-computes the denotations of an overloaded method. So it should not be done after we have pruned down those denotations by an accessibility test. We now do it before checking accessibility.

Fixes #15821

Making a package object explicit re-computes the denotations of an overloaded method.
So it should not be done after we have pruned down those denotations by an accessibility
test. We now do it before checking accessibility.

Fixes scala#15821
@odersky odersky added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Jun 26, 2023
@odersky odersky merged commit 3b5c8c0 into scala:main Jun 26, 2023
@odersky odersky deleted the fix-15821 branch June 26, 2023 16:08
@odersky
Copy link
Contributor Author

odersky commented Jun 26, 2023

It's backport nominated since it fixes a security hole. Previously, a protected member of a package object could be accessed from outside the package. This would not be caught at runtime either since protected in Scala is widened to public in bytecode. So all we have are compile time checks, and these were letting this case through.

Kordyjan added a commit that referenced this pull request Jun 28, 2023
@Kordyjan Kordyjan added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" backport:done This PR was successfully backported. and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels Jun 28, 2023
odersky added a commit to dotty-staging/dotty that referenced this pull request Jul 4, 2023
For private toplevel definitions we expand `private` to `private[p]`
where `p` is the enclosing package. This PR applies the same scheme to
protected toplevel definitions.

Rationale: 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. To avoid that we make the package explicit as qalifier.

Thsi shouls also make specs2 compile again.
odersky added a commit to dotty-staging/dotty that referenced this pull request Jul 4, 2023
For private toplevel definitions we expand `private` to `private[p]`
where `p` is the enclosing package. This PR applies the same scheme to
protected toplevel definitions.

Rationale: 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. To avoid that we make the package explicit as qalifier.

Thsi shouls also make specs2 compile again.
odersky added a commit to dotty-staging/dotty that referenced this pull request 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?

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.
Kordyjan pushed a commit to dotty-staging/dotty that referenced this pull request Jul 5, 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?

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.
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 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.

Cannot disambiguate public overload from package-private
3 participants