zls icon indicating copy to clipboard operation
zls copied to clipboard

Autocomplete always requests `self` parameter when constructed via func with comptime func return type

Open lawrence-laz opened this issue 1 year ago • 0 comments

Zig Version

0.12.0-dev.2809+f3bd17772

Zig Language Server Version

0.12.0-dev.438+8cca7a1

Client / Code Editor / Extensions

NVIM v0.10.0-dev-35f475d with lspconfig

Steps to Reproduce and Observed Behavior

Copy the code below and try calling any member function on foo_instance. Notice how auto completed method always requests to fill in the self parameter.

test Foo {
    var foo_instance = foo(true);
    foo_instance.functionFooSelf(self: Foo) // <--- self param inserted
    foo_instance.functionThisSelf(self: @This()) // <--- self param inserted
    foo_instance.functionAnySelf(self: anytype) // <--- self param inserted
}

const Foo = struct {
    pub fn functionAnySelf(self: anytype) void {
        _ = self;
    }

    pub fn functionThisSelf(self: @This()) void {
        _ = self;
    }

    pub fn functionFooSelf(self: Foo) void {
        _ = self;
    }
};

pub inline fn foo(param: anytype) TypeResolve(@TypeOf(param)) {
    return .{};
}

pub fn TypeResolve(comptime T: type) type {
    return switch (@typeInfo(T)) {
        .Pointer => |type_info| switch (type_info.size) {
            .One => switch (@typeInfo(type_info.child)) {
                .Array => Foo,
                else => type_info.child,
            },
            else => T,
        },
        else => T,
    };
}

Expected Behavior

Self parameter should be omitted when calling on a struct instance.

Relevant log output

No response

lawrence-laz avatar Feb 22 '24 16:02 lawrence-laz