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:
John Schmidt
2023-03-01 21:44:11 +01:00
committed by Veikka Tuominen
parent fea14c78d1
commit ecc0108cea
2 changed files with 38 additions and 11 deletions

View 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'