Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type inference when slicing a slice with comptime-known range #1230

Open
recursiveGecko opened this issue Jun 7, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@recursiveGecko
Copy link

Zig Version

0.11.0-dev.3322+82632aff2

Zig Language Server Version

0.11.0-dev.469+4f0762a

Steps to Reproduce

Using VS Code with the Zig extension, with the following code:

const my_slice: []const f32 = &.{1, 2, 3, 4};
std.debug.print("{d:.3}", .{ my_slice[0..2] });

Enter a dot after my_slice[0..2] to trigger auto-completion.

Expected Behavior

Since the range is comptime-known, the type of my_slice[0..2] is *[2]f32, so typing . after my_slice[0..2] should open an autocomplete window that includes *.

Actual Behavior

Autocompleted suggestions are len and ptr, but not *.

This can be further validated by assigning the subslice to a variable and inspecting its type (by hovering over it), which is reported as []const f32.

const my_subslice = my_slice[0..2];
@Techatrix
Copy link
Member

ZLS is not capable of resolving comptime-known values so it assumes that values are runtime-known. A special case that would detect a number literal being used as the start and end index when slicing could be added but anything more complex would be harder to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants