Skip to content

Tests: struct literal rules coverage (§4) #529

Closed

Description

@ehartford

Tests: struct literal rules coverage (§4)

Summary

Struct literal parsing, checking, default fields, and lowering exist, but §4.3 struct literal rules need more direct test coverage. Add behavior and compile-error tests for named/positional/block forms, default field insertion, missing required fields, duplicate/unknown fields, and rule boundaries tracked by the requirements campaign.

Spec

The affected §4.3 requirements cover struct literal construction and default field behavior. The spec expects predictable named and positional construction, default field values when fields are omitted, and diagnostics for malformed literals.

Current state

  • src/Parser.w:4128-4192 parses normal struct literals, including named and positional forms.
  • src/Parser.w:4194-4235 parses block-style struct literals.
  • src/SemaCheck.w:5884-6025 checks struct literals, including defaults and field matching.
  • src/MirLower.w:8196-8257 lowers struct literals and inserts default expressions for omitted fields.
  • Existing tests include test/spec/spec_ss04_3_default_field_values.w, test/behavior/behav_record_update.w, test/behavior/behav_record_copy.w, and test/compile_errors/err_struct_missing_required_field.w, but the campaign still marks several struct-literal rule IDs as needing coverage.

Implementation plan

  1. Map each traceability ID to a concrete test case before editing tests.
  2. Extend existing struct/default-field tests only when the new assertion naturally belongs there; otherwise create narrowly named files.
  3. Add negative tests for each malformed case with exact expected diagnostics.
  4. Include lowering-sensitive behavior tests that assert omitted defaults are evaluated and placed correctly.
  5. If a rule is already covered by an existing test, document the existing test path in the issue/PR and add only the missing cases.

Test plan

  • Behavior tests:
    • named literal with all fields,
    • positional literal if still specified as legal,
    • omitted default field,
    • multiple defaults and field order independence,
    • block-style literal if it is part of the §4.3 rule set.
  • Compile-error tests:
    • missing required field,
    • unknown field,
    • duplicate field,
    • mixing named and positional fields if illegal,
    • default expression type mismatch if not already covered.
  • Run with build, with build :fixpoint, and with build :test.

Acceptance criteria

  • Each traceability ID is covered by a named test or matched to an existing test.
  • Default field insertion is tested through runtime behavior.
  • Malformed literals produce compile-error coverage.
  • Tests cover the literal forms accepted by the parser.
  • No implementation behavior is silently weakened to satisfy tests.

Dependencies

No hard dependency. If a test exposes a parser/Sema/lowering bug, fix that root cause in the implementation patch rather than narrowing the test.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 4.3.1.19, 4.3.1.26, 4.3.1.27, 4.3.1.6, 4.3.1.7, 4.3.1.8.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing the covered surface: named/positional/block-style/defaults/missing-required all have fixtures (behav_struct_lit_*, spec_ss04_3_default_field_values, err_struct_missing_required_field); mixed named+positional rejection added (err_struct_lit_mixed_named_positional, 6c59303). The negative fixtures this issue also wanted are BLOCKED on real validation bugs filed as #632 (unknown/duplicate field + default-expr mismatch silently accepted). §4.3.

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