zls icon indicating copy to clipboard operation
zls copied to clipboard

Return type of `@fieldParentPtr` is wrong

Open leecannon opened this issue 1 year ago • 1 comments

Zig Version

0.12.0-dev.1486+234693bcb

Zig Language Server Version

0.12.0-dev.228+aa9fc0c

Steps to Reproduce

The inlay hints for the two item's below shows as Item when they should be *Item and *const Item respectively.

const Node = struct {};

const Item = struct {
    node: Node,
};

pub fn main() !void {
    {
        var node: *Node = undefined;
        const item = @fieldParentPtr(Item, "node", node);
        @compileLog(@TypeOf(item)); // @as(type, *main.Item)
    }

    {
        var node: *const Node = undefined;
        const item = @fieldParentPtr(Item, "node", node);
        @compileLog(@TypeOf(item)); // @as(type, *const main.Item)
    }
}

Expected Behavior

The return type of @fieldParentPtr is a pointer, even if ZLS is not able to determine if the pointer is const or not it shouldn't show a non-pointer type.

Actual Behavior

Return type of @fieldParentPtr is resolved as parent type instead of a pointer to the parent type.

image

leecannon avatar Nov 07 '23 23:11 leecannon

https://github.com/zigtools/zls/blob/aa9fc0c2959798a59dada05f5c099487eb12c662/src/analysis.zig#L1390

Techatrix avatar Nov 08 '23 16:11 Techatrix

The first parameter of @fieldParentPtr is now resolved through RLS so this is no longer an issue.

Techatrix avatar Jun 21 '24 00:06 Techatrix