Skip to content

allow functions prototypes to have their own scopes #15409

@wrongnull

Description

@wrongnull

Zig Version

zig-0.11.0-dev.2704+83970b6d9

Steps to Reproduce and Observed Behavior

Consider the following:

const FnProto = fn (arg1: anytype, arg2: @TypeOf(arg1.some_field)) u32;

Compiler says: error: use of undeclared identifier 'arg1'
On the other hand we can get that type using another function

fn dummy(arg1: anytype, arg2: @TypeOf(arg1.some_field)) u32 {
    _ = arg2;
    return 0;
}

const FnProto = @TypeOf(dummy);

but I think that this is not the way out. Moreover, we may face to incorrect error message if there is a declaration with the same name as the parameter

const FnProto = fn (arg1: anytype, arg2: @TypeOf(arg1.some_field)) u32;
const arg1: u64 = 0;
error: type 'u64' does not support field access

Expected Behavior

So maybe function prototypes should have their own scope?

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