zls icon indicating copy to clipboard operation
zls copied to clipboard

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

Open liponex opened this issue 9 months ago • 0 comments

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.

liponex avatar Mar 09 '25 07:03 liponex