Skip to content

Tests: coherence errors coverage (§29) #488

Closed

Description

@ehartford

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

  1. Add compile-error fixtures for local orphan and duplicate impl behavior using the existing //! expect-* harness.
  2. If the harness supports matching diagnostic codes after Emit spec'd diagnostic codes (E0901, E0951-3, E1101-2, E1201) (§29.12) #429, expect E1101 and E1102; until then, match stable diagnostic substrings.
  3. Use small package/module fixtures if necessary to prove “current package” rather than same-file behavior.
  4. 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.
  5. 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.w
  • test/compile_errors/err_coherence_duplicate_trait_impl.w
  • test/compile_errors/err_coherence_overlap_trait_impl.w if current overlap behavior lacks direct coverage
  • test/spec/spec_ss11_4_coherence_positive.w for allowed local-trait/local-type cases

Acceptance criteria

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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Covered by test/compile_errors/err_coherence_duplicate_trait_impl.w (E1102), test/compile_errors/err_coherence_overlap_trait_impl.w (direct+blanket → E1201), and test/spec/spec_ss11_4_coherence_positive.w (local-trait-for-foreign + foreign-trait-for-local both permitted). Orphan-rule coverage is shared with #533's err_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).

  2. added a commit that references this issue on Jul 4, 2026
    b8e61dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions