Repository navigation
Description
Summary
Add missing test coverage for coherence diagnostics, especially orphan and duplicate trait implementation errors. The behavior exists in sema; this issue should make those guarantees regression-proof and tie them to §29 error-code expectations.
Spec
§11.4 permits a trait implementation only when the trait or type is defined in the current package. §29.12 assigns E1101 to orphan rule violations and E1102 to duplicate trait implementations.
Current state
The sema checks exist. Sema.collect_impl_decl emits orphan rule violation: impl requires a local trait or local type at src/SemaDecl.w:1569-1575. The same function emits duplicate implementation of trait for type at src/SemaDecl.w:1710-1717. Overlap checks emit overlapping implementations of '<trait>' at src/SemaDecl.w:1547-1556.
The requirements campaign notes these diagnostics are untested for requirement IDs 29.12.1.5 and 29.12.1.6. #429 tracks adding formal diagnostic codes, so this test issue should preserve the current behavior and be easy to update to E1101/E1102 once codes are emitted.
Implementation plan
- Add compile-error fixtures for local orphan and duplicate impl behavior using the existing
//! expect-*harness. - If the harness supports matching diagnostic codes after Emit spec'd diagnostic codes (E0901, E0951-3, E1101-2, E1201) (§29.12) #429, expect
E1101andE1102; until then, match stable diagnostic substrings. - Use small package/module fixtures if necessary to prove “current package” rather than same-file behavior.
- Include a positive test showing a local trait for foreign type and a foreign trait for local type are permitted, so the negative tests do not overconstrain coherence.
- Avoid changing sema behavior in this issue unless a test exposes a real bug.
Test plan
Add:
test/compile_errors/err_coherence_orphan_trait_impl.wtest/compile_errors/err_coherence_duplicate_trait_impl.wtest/compile_errors/err_coherence_overlap_trait_impl.wif current overlap behavior lacks direct coveragetest/spec/spec_ss11_4_coherence_positive.wfor allowed local-trait/local-type cases
Acceptance criteria
- Orphan impl violations are covered by a negative test.
- Duplicate impl violations are covered by a negative test.
- Tests can be updated to assert E1101/E1102 once Emit spec'd diagnostic codes (E0901, E0951-3, E1101-2, E1201) (§29.12) #429 emits codes.
- No production behavior is weakened to make tests pass.
with build && with build :fixpoint && with build :testpass.
Dependencies
#429 for formal E1101/E1102 code emission. #435/#533 may add broader extension/coherence tests; avoid duplicate fixtures where possible.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 29.12.1.5, 29.12.1.6.
Activity
ehartford commentedon Jul 3, 2026
Covered by
test/compile_errors/err_coherence_duplicate_trait_impl.w(E1102),test/compile_errors/err_coherence_overlap_trait_impl.w(direct+blanket → E1201), andtest/spec/spec_ss11_4_coherence_positive.w(local-trait-for-foreign + foreign-trait-for-local both permitted). Orphan-rule coverage is shared with #533'serr_orphan_rule_foreign_impl.w(E1101) to avoid duplicate fixtures. Full gate green (native-compile-error-tests 685, native-spec-tests 207, GATES EXIT: 0).test: pin §11.4 coherence diagnostics + §29.8 no-shadowing rule