-
-
Notifications
You must be signed in to change notification settings - Fork 406
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Zig Version
0.15.2
ZLS Version
0.15.1
Client / Code Editor / Extensions
Zed and VSCode
Steps to Reproduce and Observed Behavior
(Looking back on this, this is probably more of an enhancement)
The interesting thing with almost of these type hints, is, that zls picks a type that a general slice can be coerced to.
Example 1:
const the_string2 = try std.fmt.allocPrintSentinel(alloc, "{s}", .{the_string}, 0); //zls thinks this is []u8
std.debug.print("type: {any}\n", .{@TypeOf(the_string2)}); //however it is [:0]u8Example 2:
const attempt2 = the_string2[0..the_string2.len] //zls thinks this is []const u8
std.debug.print("type: {any}\n", .{@TypeOf(attempt2)}); //however it is []u8Example 3:
const attempt2 = the_string2[0.. :0] //zls thinks this is []u8
std.debug.print("type: {any}\n", .{@TypeOf(attempt2)}); //however it is [:0]u8Example 4:
const attempt2 = the_string2[0..the_string2.len :0] //zls thinks this is [:0]const u8
std.debug.print("type: {any}\n", .{@TypeOf(attempt2)}); //however it is [:0]u8The problem with these types being slightly incorrect is that the confusion stacks.
Take for example the following:
const the_string2 = try std.fmt.allocPrintSentinel(alloc, "{s}", .{the_string}, 0); //returns [:0]u8
const attempt2 = the_string2[0..the_string2.len :0] //this works fine.const the_string2: []u8 = try std.fmt.allocPrintSentinel(alloc, "{s}", .{the_string}, 0); //changed to what zls assumes the return type is.
const attempt2 = the_string2[0..the_string2.len :0] //this is illegal behavior leading to a panic (ArrayIndexOutOfBounds).This can be confusing for newer people.
Expected Behavior
Log Output
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working