diff options
| author | John Schmidt <john.schmidt.h@gmail.com> | 2023-03-01 21:44:11 +0100 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-03-08 16:35:53 +0200 |
| commit | ecc0108cea97772b6e921b36d8fdc8f90d5fc6cb (patch) | |
| tree | 8b31f57cd8887de57430eb44d2c12f57fe5dd25c /test | |
| parent | fea14c78d1374af909a2f11e37fe057777f3985d (diff) | |
| download | zig-ecc0108cea97772b6e921b36d8fdc8f90d5fc6cb.tar.gz zig-ecc0108cea97772b6e921b36d8fdc8f90d5fc6cb.zip | |
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.
Diffstat (limited to 'test')
| -rw-r--r-- | test/cases/compile_errors/break_void_result_location.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/cases/compile_errors/break_void_result_location.zig b/test/cases/compile_errors/break_void_result_location.zig new file mode 100644 index 0000000000..696ea39667 --- /dev/null +++ b/test/cases/compile_errors/break_void_result_location.zig @@ -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' |
