Skip to content

Tests: trait coherence coverage (§11) #533

Closed

Description

@ehartford

Summary

Add missing test coverage for trait coherence rules in §11.4 and sealed trait implementation restrictions in §11.6. The sema diagnostics exist; this issue should make them stable.

Spec

§11.4's orphan rule requires a local trait or local type for trait impls. §11.6 includes sealed traits, which may only be implemented in their defining module. §29.12 also gives E1101/E1102/E1201 slots for coherence diagnostics.

Current state

Orphan rule enforcement is implemented at src/SemaDecl.w:1569-1575. Sealed trait external-impl rejection is implemented at src/SemaDecl.w:1577-1581. Duplicate impl rejection is at src/SemaDecl.w:1710-1717, and overlap rejection is at src/SemaDecl.w:1547-1556. The requirements campaign notes the orphan and sealed paths are not directly covered by negative tests for 11.4.1.1 and 11.6.1.9.

Implementation plan

  1. Add compile-error fixtures for orphan impl and sealed trait impl outside the defining module.
  2. Add a positive sealed trait fixture showing an impl inside the defining module remains allowed.
  3. Share fixtures with Tests: coherence errors coverage (§29) #488 where possible: Tests: coherence errors coverage (§29) #488 is focused on §29 error-code coverage, while this issue should cover §11 trait semantics.
  4. If Emit spec'd diagnostic codes (E0901, E0951-3, E1101-2, E1201) (§29.12) #429 adds diagnostic codes first, assert codes; otherwise assert stable message substrings and leave a comment referencing Emit spec'd diagnostic codes (E0901, E0951-3, E1101-2, E1201) (§29.12) #429.
  5. Keep tests small and source-level; no codegen behavior is required.

Test plan

Add:

  • test/compile_errors/err_trait_orphan_impl_rule.w
  • test/compile_errors/err_sealed_trait_impl_outside_module.w
  • test/spec/spec_ss11_6_sealed_trait_local_impl.w

If not already covered, add duplicate/overlap fixtures or point #488 at them.

Acceptance criteria

Dependencies

#488 overlaps coherence diagnostic tests. #429 may add formal diagnostic codes. #435 expands coherence to extension methods but is separate.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 11.4.1.1, 11.6.1.9.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Covered by test/compile_errors/err_orphan_rule_foreign_impl.w (foreign trait for foreign type → orphan rule violation ... [E1101], §11.4), test/compile_errors/err_sealed_trait_external_impl.w (§11.6 external sealed impl → cannot implement sealed trait ... outside its defining module), and test/spec/spec_ss11_6_sealed_local_impl.w (allowed same-module sealed impl runs). Cross-module helpers live in test/compile_errors/lib/coherence/. Verified on HEAD; full gate green (native-compile-error-tests 681, native-spec-tests 206, GATES EXIT: 0).

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