Skip to content

Do you need to say = {} on the last syntactic parameter default to make it entirely optional? #7529

Description

@lnihlen

Summary of issue:

Context in this proposal and the 2026-07-16 open discussion minutes. See the proposal for a working definition of syntactic parameters (vs. semantic).

Also please note the syntax of the default values for de-structured member variables is discussed in the proposal and also in leads question #7530.

Given this function that provides default values for fields inside the de-structured second parameter:

fn A(index: i32, {key: i32 = 0, value: i32 = 0});

The question is if a call that omits the second argument entirely, such as:

A(1);

Should compile without error, or should we require the programmer to specify that we accept an absent struct with an additional = {} as a default value on the second parameter, as in alternative B here:

fn B(index: i32, {key: i32 = 0, value: i32 = 0} = {});

Also note that the B alternative presupposes we would accept {} as a valid match to a struct function parameter with default values for every indicated member, meaning that this call would compile successfully:

A(2, {});

Details:

Note that we do not allow, currently, the following:

A(3, {.something_else = 42});  // ERROR

With the reasoning that there is already syntax to allow other members in the struct, using the , _ from in the parameter:

fn C(index: i32, {key: i32 = 0, value: i32 = 0, _});

Which would then allow example 3 to compile.

Any other information that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    leads questionA question for the leads team

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions