Skip to content

Infer type for anytype for functions like std.mem.zeroInit #2223

Open
@liponex

Description

@liponex

My proposal is to enhance autocompletion for functions like std.mem.zeroInit.
This function requires to pass a type and anytype to the function, to initialize fields to zeroes.
When we do this:

const MyStruct = struct {
    a: i32 = 1,
    b: f32, // don't have a zero value
};

const my_val1 = std.mem.zeroInit(MyStruct, .{
    .a = 2, // we don't have autocompletion
});

const my_val2 = std.mem.zeroInit(MyStruct, MyStruct{
    .a = 2, // we have autocompletion
}); // but we got a compilation error, due to uninitialized field "b"

I think, that if anonymous struct would infer type in a predefined list of functions, that will make life simpler.

Also, I don't think it's possible with no predefined list of functions. Because we don't know where anonymous struct must infer it's type from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions