astgen: fill result location with void value if no other value
With this change, `break` and `break :blk` will fill the result location with `.void_value`, ensuring that the value will be type checked. The same will happen for a for loop that contains no `break`s in it's body. Closes https://github.com/ziglang/zig/issues/14686.
This commit is contained in:
committed by
Veikka Tuominen
parent
fea14c78d1
commit
ecc0108cea
32
test/cases/compile_errors/break_void_result_location.zig
Normal file
32
test/cases/compile_errors/break_void_result_location.zig
Normal file
@@ -0,0 +1,32 @@
|
||||
export fn f1() void {
|
||||
const x: usize = for ("hello") |_| {};
|
||||
_ = x;
|
||||
}
|
||||
export fn f2() void {
|
||||
const x: usize = for ("hello") |_| {
|
||||
break;
|
||||
};
|
||||
_ = x;
|
||||
}
|
||||
export fn f3() void {
|
||||
var t: bool = true;
|
||||
const x: usize = while (t) {
|
||||
break;
|
||||
};
|
||||
_ = x;
|
||||
}
|
||||
export fn f4() void {
|
||||
const x: usize = blk: {
|
||||
break :blk;
|
||||
};
|
||||
_ = x;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:22: error: expected type 'usize', found 'void'
|
||||
// :7:9: error: expected type 'usize', found 'void'
|
||||
// :14:9: error: expected type 'usize', found 'void'
|
||||
// :18:1: error: expected type 'usize', found 'void'
|
||||
Reference in New Issue
Block a user