Skip to content

Move callconv, align, addrspace, and linksection annotation before function parameter list #22263

@mlugg

Description

@mlugg

Split out from #11834. Depends on #22261.

If callconv etc cannot reference function parameters, then it seems inconsistent for them to be written after the parameter list:

// why can't I do this? `b` is declared before the `callconv(...)` expression!
fn f(comptime b: u32) callconv(if (b) .c else .auto) void {}

So, this proposal is for a simple syntax change. callconv(...), align(...), addrspace(...), and linksection(...) annotations on functions should be moved before the parameter list, just after the fn keyword, to make it clear that function parameters are inaccessible in those expressions.

fn callconv(.c) f(comptime b: u32) void {
    _ = b;
}

A zig fmt fixup can exist for one release cycle which just moves these annotations to their new location.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingImplementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions