Skip to content

Tests: pattern forms coverage (§9) #518

Closed

Description

@ehartford

Summary

Add missing coverage for already-implemented pattern forms: one-element tuple pattern syntax, unit tuple pattern, empty array patterns, and transitive reference pattern ergonomics. This is a test issue unless the new fixtures expose a real pattern lowering bug.

Spec

§9.7 says (p) is grouping, (p,) is a one-element tuple pattern, and () matches the empty tuple (docs/with-specification.md:3612-3614). It also says [] matches empty arrays and slice patterns support fixed-size array length matching (docs/with-specification.md:3616-3628). The requirements campaign additionally tracks transitive reference pattern ergonomics for matching nested references (docs/requirements.md:3303).

Current state

Pattern sema has tuple support with arity checking (src/SemaCheck.w:6816-6837), slice support including empty/head/rest/tail binding metadata (src/SemaCheck.w:6839-6862), and struct/other pattern paths. MIR lowering has tuple pattern checks/bindings (src/MirLower.w:5175-5210, src/MirLower.w:5344-5369) and slice fixed-array length checks (src/MirLower.w:5245-5267). The requirements campaign marked the listed requirements as verified but untested (out/req-campaign/g04.tsv:144-150, out/req-campaign/g04.tsv:172).

Implementation plan

  1. Add focused spec tests for tuple grouping vs one-element tuple and () matching.
  2. Add empty-array slice-pattern tests for [0]T.
  3. Add transitive reference pattern tests using the simplest currently supported reference form; if the implementation does not support the exact transitive requirement, split that out as an implementation bug rather than weakening the test.
  4. Avoid duplicating Positional struct patterns: Point(x, y) (§9.7) #468 positional struct patterns, Refutable parameter patterns / multiple function clauses (§9.7) #472 refutable parameter clauses, and Bug: slice ..rest binding fails MIR lowering (§9.7) #474 slice ..rest binding. This issue can mention them but should not claim their coverage.

Test plan

Add test/spec/spec_ss09_7_pattern_forms_more.w:

  • match (1,): (x,) => assert(x == 1).
  • match (): () => assert(true).
  • prove (x) is grouping by matching an i32 with (x).
  • match empty_array: [] => assert(true).

Add test/spec/spec_ss09_7_reference_pattern_transitive.w:

  • match a nested reference/tuple shape that should bind through references according to the requirement.

Add compile-error coverage if (x,) against a scalar or [] against a non-empty fixed array currently has a useful diagnostic.

Acceptance criteria

Dependencies

#468, #472, and #474 for adjacent pattern implementation gaps.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 9.7.1.23, 9.7.1.24, 9.7.1.29, 9.7.1.51.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing the covered surface: one-element tuple pattern (x,) + grouping pinned by spec_ss09_7_one_element_tuple_pattern (6c59303); empty-array [] by slice_pat_empty; transitive reference by spec_ss09_7_reference_pattern_ergonomics. The ONE remaining sub-form — unit-tuple () pattern — is unimplemented and filed as #631 (not a coverage gap, a feature gap). §9.7.

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