mirror of
https://github.com/ziglang/zig.git
synced 2025-12-17 19:53:06 +00:00
error on undefined end index
This commit is contained in:
parent
e8f28cda9e
commit
b87baad0ff
@ -32507,7 +32507,7 @@ fn analyzeSlice(
|
|||||||
const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);
|
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);
|
break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
|
||||||
} else try sema.coerce(block, Type.usize, uncasted_end_opt, 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(
|
const len_s_val = try mod.intValue(
|
||||||
Type.usize,
|
Type.usize,
|
||||||
array_ty.arrayLenIncludingSentinel(mod),
|
array_ty.arrayLenIncludingSentinel(mod),
|
||||||
|
|||||||
10
test/cases/compile_errors/slice_end_index_undefined.zig
Normal file
10
test/cases/compile_errors/slice_end_index_undefined.zig
Normal 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
|
||||||
Loading…
x
Reference in New Issue
Block a user