Skip to content

Missing compile error for reassigning parameter #4350

Closed
@jayschwa

Description

@jayschwa

Possibly related to #788.

I have a piece of code that processes smaller sequential slices of a larger slice. Rather than getting a slice of length zero at the end, I get a segmentation fault.

const std = @import("std");

const CHUNK_LEN = 2;

fn slice_to_zero(input: []const u8) void {
    while (input.len > 0) {
        const take = std.math.min(input.len, CHUNK_LEN);
        _ = input[0..take]; // Imagine this slice chunk is used for something
        input = input[take..];
    }
}

test "slicing down to zero length" {
    slice_to_zero("");
    slice_to_zero("foo");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions