Skip to content

Conversation

@bracevac
Copy link
Contributor

Fixes #18446

@bracevac bracevac marked this pull request as ready for review January 8, 2025 14:56
@lrytz
Copy link
Member

lrytz commented Jan 15, 2025

It seems the right place to fix this is SymDenotation.isAccessibleFrom.

I think this line in accessBoundry is too permissive https://github.com/scala/scala3/blob/3.6.2/compiler/src/dotty/tools/dotc/core/SymDenotations.scala#L1465, it treats java static protected as public.

Removing that line makes poll inaccessible in subclasses of Task, which is too strict. The isProtectedAccessOK method doesn't handle this case correctly in Scala 3, owner.enclosingSubClass returns NoSymbol because the poll method is in the Task$ companion module, not in the Task class. I think Scala 2 does it correctly (isProtectedAccessOK uses enclosingSubClassContext, which calls isSubClassOrCompanion). Here are two fixes that went into Scala 2 but weren't forward ported to 3: scala/scala@01c3bbb and scala/scala@0b92c3c.

I think it's worth fixing the issue at that level because isAccessibleFrom is not only used to check accessibility during symbol lookup, but also for example in completions, Denotation.meet, and others.

@bracevac bracevac closed this Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler should not allow to access Java protected static method defined in different package

3 participants