Skip to content

Proposal: Optional argument names in function calls #982

Closed
@alexnask

Description

@alexnask

Proposed syntax:

fn foo(a: u8, b: usize, c: []const u8) void {}

test "optional argument names" {
    foo(c: "Hi!", 0, 42); // -> foo(0, 42, "Hi!");
    foo(a: 0, c: "bar", 10); // -> foo(0, 10, "bar");
}

Invalid argument names obviously cause a compile error.
To match the arguments, we simply look at the named arguments first, then match the rest in the same order they appear in the function definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions