Skip to content

Tests: named args coverage (§9) #508

Closed

Description

@ehartford

Summary

Add missing negative and edge-case tests for named arguments. Core named calls already work, but the test suite does not fully lock down parser rejection, call-site default evaluation, and named-arg exclusions.

Spec

§9.1a requires positional arguments before named arguments, default expressions evaluated at the call site on every omitted call, and no named arguments for extern fn values, closure values, or placeholder partial application (docs/with-specification.md:3083-3102). §9.4 also forbids named arguments in placeholder calls (docs/with-specification.md:3362-3372).

Current state

Parser emits positional argument cannot follow named argument (src/Parser.w:4039-4040). Sema rejects named args on closures/function pointers (src/SemaCheck.w:7835-7839) and fills named/default arguments (src/SemaCheck.w:7855-7929). test/behavior/behav_named_args.w:15-44 covers positive named calls, mixed calls, defaults, and reordering. The requirements campaign still records missing coverage for parser rejection, per-call default evaluation, and closure rejection (out/req-campaign/g04.tsv:43, out/req-campaign/g04.tsv:48, out/req-campaign/g04.tsv:50).

Implementation plan

  1. Add compile-error coverage for positional-after-named syntax using the parser diagnostic.
  2. Add behavior coverage proving default expressions are evaluated on every call, not once at declaration or first use. Use a global or local counter only if Enforce the §9.1c global data-race rule (conservative single-thread proof) #387's global rule has landed; otherwise use a helper returning different values through existing safe local state.
  3. Add compile-error coverage for named args on closure values and extern "C" fn values using the current sema diagnostic.
  4. Add placeholder+named coverage after Named-args rule gaps: implicit+default rejection, placeholder+named rejection (§9.1a, §9.4) #456 implements the rule; until then, reference Named-args rule gaps: implicit+default rejection, placeholder+named rejection (§9.1a, §9.4) #456 from this test issue.
  5. Update the stale spec test comments in test/spec/spec_ss09_1a_named_arguments_and_implicit_context.w.

Test plan

Add test/compile_errors/err_named_arg_positional_after_named.w with add(a: 1, 2) and //! expect-error: positional argument cannot follow named argument.

Add test/behavior/behav_named_arg_default_eval_each_call.w:

  • default expression increments or reads changing state.
  • two calls omitting the default observe two evaluations.

Add test/compile_errors/err_named_arg_closure_value.w:

  • let f = x => x + 1; f(x: 1) expects named arguments are not supported for closures or function pointers.

Add test/compile_errors/err_named_arg_extern_fn_value.w if extern function pointer syntax allows a direct value call.

After #456, add test/compile_errors/err_named_arg_partial_placeholder.w.

Acceptance criteria

Dependencies

#456 for placeholder+named rejection. #397 for stale spec-test cleanup. #387 if the default-evaluation test uses mutable globals.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 9.1.2.10, 9.1.2.3, 9.1.2.8.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing — named args: positional-after-named rejection (err_named_arg_positional_after_named), closure named-arg rejection (err_named_arg_closure_value), and per-call default-expr evaluation (behav_named_arg_default_eval_each_call) pinned (bfe7865); placeholder+named already covered by err_partial_app_named_arg. §9.

  2. added a commit that references this issue on Jul 4, 2026
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