zig icon indicating copy to clipboard operation
zig copied to clipboard

Compiler crashes when taking slice with undefined end index

Open GigaGrunch opened this issue 1 year ago • 1 comments

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

Run zig build-exe on a file with this code:

pub fn main() void {
    var array: [0]void = undefined;
    _ = array[0..undefined];
}

My compiler on Windows just crashes with a segmentation fault.


I actually started with completely different code and used zig reduce to get to this minimal setup. I'm not sure if this crash is even the same as the one I started out with. So just for the sake of documentation, I'll post a link to the commit in my repository where it all started: trecker/4ba6f72

Expected Behavior

Maybe an error message because I did something stupid, but definitely not a compiler crash.

GigaGrunch avatar Apr 22 '24 14:04 GigaGrunch

This line should use resolveDefinedValue. https://github.com/ziglang/zig/blob/6fd09f8d2d50525e3f58213e44f815ed577c2864/src/Sema.zig#L32510

Vexu avatar Apr 22 '24 14:04 Vexu