You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Duplicate explicit imports resolve silently last-wins (no ambiguity error) #993
Silent name-resolution defect (audit finding IMPORT-001). Deterministic but fragile: reordering use lines changes which function is called with no diagnostic.
Source chain
Two explicit imports of the same name (use a.helper + use b.helper) pass with check silently; at runtime the LAST import wins (probe prints 2; .audit/probes/import_ambig/). Spec §18.2 defines precedence tiers but is silent on collisions within the explicit-import tier — while mandating a hard ambiguity error for the lower stdlib-fallback tier ('Two or more standard-library candidates for one name is a hard ambiguity error'). The language forbids local rebinding/shadowing yet silently shadows at import scope: the strictness is inverted across tiers.
Repair boundary
Either emit the same hard ambiguity error for duplicate explicit imports (with both candidates shown, consistent with the fallback tier), or bless last-wins explicitly in §18.2 with a same-file duplicate-import lint. The silent middle (no error, no spec text) is the defect.
Same defect class, wider scope: duplicate TYPE declarations are also silently last-wins (type Dup { v: i32 } then type Dup { w: i32 } checks clean; constructing with v fails as 'unknown field' — first decl invisible; probes .audit/probes/readonly_pass_20260903/duptype{,2}_probe.w). But duplicate FUNCTIONS are rejected ('function is already defined', probe dupfn_probe.w). So the duplicate check exists for one declaration-table path and is missing for types and imports alike — the fix is one rule applied uniformly, and the fn diagnostic is the template.
Review: reproduced (imports and types; functions are the control that works)
Verdict. Established on current main. Two explicit imports of the same name from different modules pass with check and the later use line silently wins: swapping the two lines changes the program's output with no diagnostic. The follow-up comment's wider claim also holds: two type Dup declarations in one file check clean and the first becomes invisible (constructing with its field reports unknown field), while two fn f declarations are correctly rejected with function 'f' is already defined. So the duplicate-declaration rule exists for one table and is missing for the other two.
use a.helper then use b.helper; print(f"{helper()}")
ok
2
use b.helper then use a.helper; same body
ok
1
type Dup { v: i32 } then type Dup { w: i32 }; Dup { v: 1 }
error: unknown field 'v' for type 'Dup' (first declaration silently replaced; no duplicate diagnostic)
n/a
control: fn f() -> i32: 1 then fn f() -> i32: 2
error: function 'f' is already defined at the second declaration
n/a
Source
Function duplicates are rejected at src/SemaDecl.w:1532 (is already defined) and :1803 (extern shadowing a fn). grep finds no counterpart diagnostic for imports (already imported, ambiguous import, duplicate import) anywhere in src/Sema*.w or src/Resolve.w.
Named types are registered by an unconditional named_types.insert(sym, tid) at src/Sema.w:2604; a second insert for the same symbol replaces the first, which is exactly the observed "first declaration invisible" behaviour.
§18.2 (spec line 10337 onward) defines the precedence tiers and says of tier 5 that "two or more standard-library candidates for one name is a hard ambiguity error", but says nothing about two candidates within tier 3 (explicit imports). The report's characterisation that strictness is inverted across tiers is accurate.
The spec has no text at all on duplicate type declarations in one module (no "already defined", "redefinition", or "declared twice" anywhere), so the type case is unspecified rather than contradicted; the function diagnostic shows the intended rule.
§29.8 is cited by the spec itself as "the no-shadowing rule" (line 8657); silent last-wins at import and type scope is shadowing by another name.
Related PRs
None merged or open address import or type duplicate detection.
Would I champion a fix? Yes, one rule applied uniformly.
Acceptance criteria:
Two explicit imports (or an import and an alias) binding the same unqualified name in one module produce a hard error naming both candidates, mirroring the tier-5 wording, unless they resolve to the same declaration (re-importing the same item twice can be a lint).
A second type/enum/trait declaration with the same name in one module produces the same 'X' is already defined error the function path emits, anchored at the second declaration with a note at the first.
test/compile_errors fixtures for both, and the two probe programs above become negative fixtures.
§18.2 gains one sentence stating the within-tier ambiguity rule, authored by the maintainer.
Untested
Glob/module-level imports (use a.* style, if supported) and cross-file duplicates of the same type name in different modules were not probed; the latter is legitimately allowed by module scoping and is not the defect here.
Activity
eas4ai commentedon Sep 3, 2026
Same defect class, wider scope: duplicate TYPE declarations are also silently last-wins (
type Dup { v: i32 }thentype Dup { w: i32 }checks clean; constructing withvfails as 'unknown field' — first decl invisible; probes.audit/probes/readonly_pass_20260903/duptype{,2}_probe.w). But duplicate FUNCTIONS are rejected ('function is already defined', probedupfn_probe.w). So the duplicate check exists for one declaration-table path and is missing for types and imports alike — the fix is one rule applied uniformly, and the fn diagnostic is the template.ehartford commentedon Sep 16, 2026
Review: reproduced (imports and types; functions are the control that works)
Verdict. Established on current
main. Two explicit imports of the same name from different modules passwith checkand the lateruseline silently wins: swapping the two lines changes the program's output with no diagnostic. The follow-up comment's wider claim also holds: twotype Dupdeclarations in one file check clean and the first becomes invisible (constructing with its field reportsunknown field), while twofn fdeclarations are correctly rejected withfunction 'f' is already defined. So the duplicate-declaration rule exists for one table and is missing for the other two.Tested revision and compiler
main@ 5809ac1 (2026-09-14)with buildof 5809ac1 in a detached worktree, self-reportswith v0.15.2.1Probes
a.w:pub fn helper() -> i32: 1;b.w:pub fn helper() -> i32: 2.with checkwith runuse a.helperthenuse b.helper;print(f"{helper()}")use b.helperthenuse a.helper; same bodytype Dup { v: i32 }thentype Dup { w: i32 };Dup { v: 1 }error: unknown field 'v' for type 'Dup'(first declaration silently replaced; no duplicate diagnostic)fn f() -> i32: 1thenfn f() -> i32: 2error: function 'f' is already definedat the second declarationSource
src/SemaDecl.w:1532(is already defined) and:1803(extern shadowing a fn).grepfinds no counterpart diagnostic for imports (already imported,ambiguous import,duplicate import) anywhere insrc/Sema*.worsrc/Resolve.w.named_types.insert(sym, tid)atsrc/Sema.w:2604; a second insert for the same symbol replaces the first, which is exactly the observed "first declaration invisible" behaviour.Spec
typedeclarations in one module (no "already defined", "redefinition", or "declared twice" anywhere), so the type case is unspecified rather than contradicted; the function diagnostic shows the intended rule.Related PRs
None merged or open address import or type duplicate detection.
Would I champion a fix? Yes, one rule applied uniformly.
Acceptance criteria:
type/enum/traitdeclaration with the same name in one module produces the same'X' is already definederror the function path emits, anchored at the second declaration with a note at the first.test/compile_errorsfixtures for both, and the two probe programs above become negative fixtures.Untested
Glob/module-level imports (
use a.*style, if supported) and cross-file duplicates of the same type name in different modules were not probed; the latter is legitimately allowed by module scoping and is not the defect here.Sema: the later import shadows the earlier (§18.2, Eric's ruling; Fixes
Sema: the later import shadows the earlier (§18.2, Eric's ruling; Fixes
Sema: the later import shadows the earlier (§18.2, Eric's ruling; Fixes
Sema: the later import shadows the earlier (§18.2, Eric's ruling; Fixes
Sema: the later import shadows the earlier (§18.2, Eric's ruling; Fixes
Sema: the later import shadows the earlier (§18.2, Eric's ruling; Fixes
Spec-ruled fixes: Some(place) borrows for Option[&T], module globals …