aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2023-03-01 21:44:11 +0100
committerVeikka Tuominen <git@vexu.eu>2023-03-08 16:35:53 +0200
commitecc0108cea97772b6e921b36d8fdc8f90d5fc6cb (patch)
tree8b31f57cd8887de57430eb44d2c12f57fe5dd25c /test/cases/compile_errors
parentfea14c78d1374af909a2f11e37fe057777f3985d (diff)
downloadzig-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/cases/compile_errors')
-rw-r--r--test/cases/compile_errors/break_void_result_location.zig32
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'