zls
zls copied to clipboard
Return type of `@fieldParentPtr` is wrong
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.
https://github.com/zigtools/zls/blob/aa9fc0c2959798a59dada05f5c099487eb12c662/src/analysis.zig#L1390
The first parameter of @fieldParentPtr is now resolved through RLS so this is no longer an issue.