zls icon indicating copy to clipboard operation
zls copied to clipboard

🐛 Incorrect inferred type for variable declaration

Open vegerot opened this issue 10 months ago • 1 comments

Zig Version

0.13.0

ZLS Version

0.13.0

Client / Code Editor / Extensions

NVIM v0.11.0-dev-1664+ge71d2c817d / nvim-lspconfig

Steps to Reproduce and Observed Behavior

zls incorrectly says the type of const arr = .{ "1", "22" }; is [2]*const [1:0]u8 when it's actually struct{comptime *const [1:0]u8 = "1", comptime *const [2:0]u8 = &.{ 50, 50 }}

Image
const std = @import("std");
pub fn main() void {
    const arr = .{ "1", "22" };
    std.debug.print("type of arr: {}\n", .{@TypeOf(arr)});
}

If I were to put zls' inferred type here, then it'd be

    const arr: [2]*const [1:0]u8 = .{ "1", "22" }; // expected type '*const [1:0]u8', found '*const [2:0]u8'

Expected Behavior

My main issue is the inlay type

Image

imo the way this hint is displayed, the expectation should be that changing the hint into real code should work.

vegerot avatar Feb 03 '25 23:02 vegerot

this looks like https://github.com/zigtools/zls/issues/2065

xdBronch avatar Feb 04 '25 00:02 xdBronch

The inlay hint now displays struct{ *const [1:0]u8, *const [2:0]u8 }.

Techatrix avatar Apr 06 '25 17:04 Techatrix