Repository navigation
Description
Tests: default builtins coverage (§4)
Summary
The compiler implements implicit default-return support for several built-in and library types, but the requirements campaign still needs tests for the §4.10 default builtins. Add spec-mapped tests for unsigned integers, usize, str, Vec, HashMap, and HashSet defaults, including both Sema acceptance and actual lowered values.
Spec
docs/with-specification.md:2130-2212 defines implicit default return and lists default values for built-ins: integers default to zero, str defaults to "", Option defaults to None, Vec/HashMap/HashSet default to empty collections, and compatible Result defaults to Ok(T.default()).
Current state
src/SemaCheck.w:8999-9025recognizes defaultable types including primitive ints/floats/bool/str/pointers, arrays/ranges/tuples,Option,Vec,HashMap,HashSet,Result, andDefaulttrait implementers.src/ComptimeEval.w:837-895has a comptime default-value helper for several of these cases.src/MirLower.w:7440-7445only emits implicit defaults forvoid,bool, and integer types in the normal MIR path. This may make some Sema-accepted default tests expose an implementation bug.test/spec/spec_ss04_10_implicit_default_return.wcovers important positive cases, but the campaign IDs specifically call out default builtins that still need direct coverage.
Implementation plan
- Add tests for the required default builtins using functions that fall through with only
Unitstatements. - Start with types that Sema and MIR both support; for Sema-accepted but MIR-missing types, either implement the missing lowering or split an implementation issue instead of writing tests that cannot pass.
- Cover collection emptiness through
len()/membership APIs rather than inspecting internals. - Include both runtime and comptime default paths if both are intended to support the type.
- Keep mixed-body rejection out of this issue; Implicit default return: apply only when the body has no explicit value return #382 owns the rule that disables defaulting when explicit value returns exist.
Test plan
- Add or extend
test/spec/spec_ss04_10_implicit_default_return.wwith:- unsigned integer default (
u32oru64), usizedefault,strdefault,Vec[i32]empty default,HashMap[str, i32]empty default,HashSet[str]empty default.
- unsigned integer default (
- Add comptime equivalents where the evaluator supports the type.
- If
HashSetlacks enough public API for emptiness, add the smallest available assertion or split that stdlib/testability gap. - Run
with build,with build :fixpoint, andwith build :test.
Acceptance criteria
- Each traceability ID has direct default-value coverage.
- Tests assert actual default values, not just successful compilation.
- Collection defaults are proven empty through public APIs.
- Runtime and comptime behavior are either both covered or explicitly split.
- Any Sema/MIR default mismatch is fixed or filed loudly.
Dependencies
Related to #382 for mixed-body defaulting and to any follow-up needed to broaden src/MirLower.w:7440-7445 beyond primitive defaults.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 4.10.1.10, 4.10.1.11, 4.10.1.12, 4.10.1.4, 4.10.1.5, 4.10.1.8.
Activity
ehartford commentedon Jul 3, 2026
Closing the covered surface: implicit-default of u32/usize/str/Vec pinned by spec_ss04_10_default_builtins (6c59303). HashMap/HashSet implicit-default SEGFAULTS — filed as #633 (a codegen bug, not a coverage gap). §4.10.
test: coverage-sweep batch 1 (#495 #496 #521 #518 #529 #492 #499)