Skip to content

Enclosing package p.q not visible as q #23069

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Apr 29, 2025

Fixes #23047

Normally, an enclosing definition always has higher "name binding" precedence than an import, but an enclosing packaging can have a dotted name with a simple name that can't be referenced without qualification or import.

This first cut gives up, but we can infer whether a package was introduced with a dotted name by comparing the owner of the current context with the enclosing package owner.

The second commit does that clever thing (which is not necessarily a good thing).

@som-snytt som-snytt force-pushed the issue/23047-pkg-import branch 3 times, most recently from fca2ca4 to 05fc3cd Compare April 30, 2025 03:06
@som-snytt
Copy link
Contributor Author

It's been a while since I ran the lint on the dotty code base.

end if
done = true
else
return // found enclosing definition, don't register the reference
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This special handling isn't necessary. Just set a flag for "found enclosing" (so don't register reference), then in outer context it will find the member (for "simple package" or other defs) and not find the "hidden" dotted package name. The latter case won't terminate right away (but that could be fixed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I already told tpolecat that I deleted the return.

@som-snytt som-snytt force-pushed the issue/23047-pkg-import branch from 05fc3cd to bea7edc Compare April 30, 2025 23:23
@@ -419,7 +419,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
candidate = cur
importer = sel
else if checkMember(cur.owner) then
if sym.srcPos.sourcePos.source == ctx.source then
if sym.is(Package) || sym.srcPos.sourcePos.source == ctx.source then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package sym has no source to compare.

@som-snytt som-snytt force-pushed the issue/23047-pkg-import branch from bea7edc to 06d1611 Compare April 30, 2025 23:29
@som-snytt som-snytt marked this pull request as ready for review May 1, 2025 03:35
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.

False positive warning: Unused import of a package
1 participant