Repository navigation
Description
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-4192parses normal struct literals, including named and positional forms.src/Parser.w:4194-4235parses block-style struct literals.src/SemaCheck.w:5884-6025checks struct literals, including defaults and field matching.src/MirLower.w:8196-8257lowers 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, andtest/compile_errors/err_struct_missing_required_field.w, but the campaign still marks several struct-literal rule IDs as needing coverage.
Implementation plan
- Map each traceability ID to a concrete test case before editing tests.
- Extend existing struct/default-field tests only when the new assertion naturally belongs there; otherwise create narrowly named files.
- Add negative tests for each malformed case with exact expected diagnostics.
- Include lowering-sensitive behavior tests that assert omitted defaults are evaluated and placed correctly.
- 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, andwith 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
ehartford commentedon Jul 3, 2026
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.
test: coverage-sweep batch 1 (#495 #496 #521 #518 #529 #492 #499)