Skip to content

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

@recursiveGecko

Description

@recursiveGecko

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];

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions