Skip to content

Tests: derive coverage (§11) #494

Closed

Description

@ehartford

Summary

Add targeted derive tests for behavior that exists but is not regression-protected. This issue is test-only unless the new tests expose a mismatch with §11.8.

Spec

§11.8 says derive(all) derives every eligible trait the type qualifies for, but does not infer Copy for aggregates. It also allows derive requests where ineligible traits are skipped by design in specific conservative cases instead of producing an error.

Current state

The main derive spec test covers common positive behavior: Eq, Hash, Debug, Clone, Default, derive(all), and explicit Copy at test/spec/spec_ss11_8_derive.w:3-78. Builder coverage exists at test/spec/spec_ss11_8_derive_builder.w:3-40. The requirements campaign still found missing tests for 11.8.1.15 and 11.8.1.16: the silent-skip path and the “no error by design” path.

#409 owns implementation gaps such as Ord, enum Display, and user-defined derives. This issue should not duplicate that implementation work.

Implementation plan

  1. Identify the exact current derive paths that intentionally skip instead of erroring, likely in ComptimeTransform.w derive generation and sema derive validation.
  2. Add positive tests that assert skipped traits are absent via comptime T.implements(Trait) and that compilation succeeds.
  3. Add negative tests only for cases the spec says must error, such as explicit @[derive(Copy)] with a non-Copy field.
  4. Keep these tests independent of Complete derive targets: Default, Hash, Ord, Display, derive(all), derive(Builder) (§11.8) #409's unimplemented Ord/Display targets unless Complete derive targets: Default, Hash, Ord, Display, derive(all), derive(Builder) (§11.8) #409 lands first.
  5. Update test names to state the rule, not the implementation accident.

Test plan

Add test/spec/spec_ss11_8_derive_skip_semantics.w:

  • @[derive(all)] on a type with a non-Default or non-Hash field skips only the ineligible trait if that is current/spec behavior.
  • @[derive(all)] never makes the type Copy.
  • Explicit eligible derives still work on the same type.

Add/verify compile-error cases:

  • explicit @[derive(Copy)] on non-Copy field
  • explicit derive of a target whose required field method is missing, if §11.8 requires an error rather than skip.

Acceptance criteria

Dependencies

#409 may change the exact eligible target list; land this after or coordinate expected outcomes.

Traceability

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

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing — derive(all) derives eligible traits and silently skips ineligible ones (Default here) without inferring Copy, and derive(Copy) on non-Copy fields is rejected: spec_ss11_8_derive_skip + err_derive_copy_noncopy (ec03406). §11.8.1.15/16.

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