Repository navigation
Conversation
…mber An unqualified name was looked up among the members every enclosing namespace owns before the imports of the namespace the walk had reached, so a name imported by an enclosing namespace lost to a same-named member owned further out. The walk now consults a namespace's imports before the namespaces around it, and the look-ahead over enclosing owned members stops at the nearest namespace importing the name (KerML 8.2.3.5.4). Fixes #2666 Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
There was a problem hiding this comment.
Devin Review found 2 findings. Devin fixed 1 finding; 1 finding is left for you to triage below.
Fixed by Devin (1)
- Unqualified calls run the shadowed calculation — Confirmed: a call to f() two packages inside
private import Q::*evaluated the outer P::f (1) instead of Q::f (2). unqualifiedCandidates now follows the same order as walkUnqualifiedHiding; failing-first test added. Committed locally, not pushed yet (push waits for the CI coordinator's GO).
| if sym, ok := r.importedName(scope, name, hide); ok { | ||
| return nil, scope, sym |
There was a problem hiding this comment.
🔴 Wildcard imports expose shadowed members
When an enclosing import shadows a wildcard target’s qualifier, enclosingLocal selects the nearer qualifier. resolveWildcardTarget still indexes the outer target when the nearer qualifier’s subtree has no index entry under its imported name. Qualified references then resolve members the wildcard import did not bring in.
Devin left this for you to triage: Confirmed: with package K { private import Q::X; package N { public import X::*; } } inside a P that owns its own X, N re-exports the members of both P::X (through the symbol index) and Q::X (through the resolver). The index records only wildcard imports, so it cannot see K's membership import; develop has the mirror-image mismatch when K's import is a wildcard, which this PR fixes. A proper fix needs the index and its cache snapshot to record membership imports; I recommend a separate issue and PR rather than widening this one.
Learn more
walkQualified resolves the leading qualifier lexically before walking the remaining segments. resolveWildcardTarget instead tries the complete target under each enclosing package prefix. A wildcard re-export of a package indexes that package's name but not its subtree, so the closer prefix can lack the full target key. expandImporter then records public re-exports from the farther target. When the direct import lookup misses one of those members, membersNamed accepts the indexed re-export.
Example: Declare L::Q::D::New and P::Q::D::Old in separate package trees. Inside P::K, write public import L::*; and declare package N { public import Q::D::*; }. The import in N now points to L::Q::D, but the index still expands P::Q::D because it cannot find P::K::Q::D as a full key. A usage typed by P::K::N::Old therefore still finds Old through the index, although the import only brings in New.
Recommended fix: Make wildcard expansion resolve the leading segment before following the target's remaining segments, using the same precedence as semantic lookup. Do not admit a fallback re-export that disagrees with the resolved import target. Add a workspace regression with the expanded index that accepts P::K::N::New and rejects P::K::N::Old.
Was this helpful? React with 👍 or 👎 to provide feedback.
What and why
A name imported by an enclosing namespace now resolves before a same-named member owned further out. Closes #2666.
Behaviour change to review first: a package that imports its own name no longer names itself from inside. The leading segment of a qualified name follows the same lookup order, so in
the reference is unresolved where it used to resolve. The pinned pilot validator reports the same reference unresolved.
$::V::Grade::high,Grade::high, or importing the units by name all still resolve.Two consequences of that in this PR:
internal/frontend/repl/import_test.gohad exactly this shape, so its model now importsSI::kgandSI::minstead ofSI::*. The assertions are unchanged.%importwrites enumeration values as unrooted qualified names, so it cannot set one in a package that imports its own name by wildcard.The bug
walkUnqualifiedHidingsearched the members every enclosing scope declares before the imports of the scope it was standing in, soP::Twon over the nearerK's import and no diagnostic was reported. It now takes a scope's imports first, then walks outward only as far as the nearest scope that imports the name. A member the nearer namespace owns or inherits still comes first, and an outer member is still found when no namespace between imports the name.The second commit makes that outward walk happen once per lookup instead of once per scope level.
Specification basis
KerML 8.2.3.5.4 (local resolution): a name that is not a membership of the local namespace resolves in the enclosing namespace, whose memberships include its imported ones. Adds a row to
docs/project/spec-compliance/02-detailed-semantic-compliance-map/28-name-resolution.md.How it was verified
Failing first: with
develop'sunqualified.go, the new test reports the wrong owner.With the fix all three new tests pass. They assert the resolved owner, across wildcard and membership imports in a package, a definition, a usage, a state and action bodies, with the nearer-member and no-import controls. Try it:
Run locally on this head, after merging
develop:go build ./...,go vet ./...,gofmt -l .(empty),make lintgo test -count=1 ./...go test ./tests/corpuswithOPENSYSML_REQUIRE_TRAINING_CORPUS,OPENSYSML_REQUIRE_PILOT_CORPORAandOPENSYSML_REQUIRE_SPEC_EXAMPLESset: no baseline movedRun before the
developmerge and the second commit, not repeated since:go test -C tools ./...andderived-census -check -recorded-pilot.Not run: the race detector.
Benchmarks
go test ./tests/perf -run '^$' -bench '^Benchmark(Analyze|AnalyzeManyDiagnostics|LookupQualified|REPLLoadFile|WorkspaceEdit|FeaturesOf)$' -benchmem -count=8,develop'sunqualified.goagainst this branch's, same machine, compared withbenchstat.~is no significant difference (p > 0.05, n = 8).WorkspaceEdit/vehicle/reindex+diagnostics: +6.4% bytes and +5.8% allocations, time unchanged. A scope's imports are now consulted before its enclosing scopes' members, which is the corrected order.developmerge.Checklist
make testandmake lintpass locally (go test ./...without-race;make lintpasses)changes/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (none moved)F4,K5) in the body, docs, or changelogImplemented in session Fix enclosing import losing to outer member
Review with Devin · Open in Devin Desktop