error on undefined end index

This commit is contained in:
David Rubin 2024-04-22 07:14:02 -07:00 committed by Veikka Tuominen
parent e8f28cda9e
commit b87baad0ff
2 changed files with 11 additions and 1 deletions

View File

@ -32507,7 +32507,7 @@ fn analyzeSlice(
const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);
break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
} else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
if (try sema.resolveValue(end)) |end_val| {
if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
const len_s_val = try mod.intValue(
Type.usize,
array_ty.arrayLenIncludingSentinel(mod),

View File

@ -0,0 +1,10 @@
export fn a() void {
var array: [0]void = undefined;
_ = array[0..undefined];
}
// error
// backend=stage2
// target=native
//
// :3:18: error: use of undefined value here causes undefined behavior