Skip to content

Tests: default builtins coverage (§4) #492

Closed

Description

@ehartford

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-9025 recognizes defaultable types including primitive ints/floats/bool/str/pointers, arrays/ranges/tuples, Option, Vec, HashMap, HashSet, Result, and Default trait implementers.
  • src/ComptimeEval.w:837-895 has a comptime default-value helper for several of these cases.
  • src/MirLower.w:7440-7445 only emits implicit defaults for void, 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.w covers important positive cases, but the campaign IDs specifically call out default builtins that still need direct coverage.

Implementation plan

  1. Add tests for the required default builtins using functions that fall through with only Unit statements.
  2. 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.
  3. Cover collection emptiness through len()/membership APIs rather than inspecting internals.
  4. Include both runtime and comptime default paths if both are intended to support the type.
  5. 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.w with:
    • unsigned integer default (u32 or u64),
    • usize default,
    • str default,
    • Vec[i32] empty default,
    • HashMap[str, i32] empty default,
    • HashSet[str] empty default.
  • Add comptime equivalents where the evaluator supports the type.
  • If HashSet lacks enough public API for emptiness, add the smallest available assertion or split that stdlib/testability gap.
  • Run with build, with build :fixpoint, and with 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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    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.

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