Files
zig/test/cases/compile_errors/break_void_result_location.zig
John Schmidt ecc0108cea 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.
2023-03-08 16:35:53 +02:00

33 lines
639 B
Zig

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'