Skip to content

disallow slicing many-pointer with sentinel without end index #22345

@Techatrix

Description

@Techatrix

The following code currently compiles without errors:

const std = @import("std");
const assert = std.debug.assert;

test {
    var foo: [*]const u8 = &.{ 1, 2 };
    _ = foo[0.. :0];
    comptime assert(@TypeOf(foo[0.. :0]) == [*]const u8);
}

The sentinel expression is being analyzed but has does nothing.

I can think of two possible ways to resolve this:

  • disallow ptr[start.. :sentinel] on a multi item pointer (or C pointer)
  • resolve to [*:0]const u8

The problem with the second option is that it is not possible to implement a safety check for it.

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions