diff options
| author | kkHAIKE <kkhaike@gmail.com> | 2022-09-17 20:16:40 +0800 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-09-21 20:21:02 +0300 |
| commit | 4961044ce8d06f43bf6f43c103433d70a1fbd79a (patch) | |
| tree | 8a80cdc1f4bd24380b511aaf425da697ca910933 | |
| parent | 183127733c8ab51c05f4d4b5cee2a1497272172a (diff) | |
| download | zig-4961044ce8d06f43bf6f43c103433d70a1fbd79a.tar.gz zig-4961044ce8d06f43bf6f43c103433d70a1fbd79a.zip | |
AstGen: store void to ptr result loc when there is no else branch
| -rw-r--r-- | src/AstGen.zig | 6 | ||||
| -rw-r--r-- | test/cases/compile_errors/missing_else_clause.zig | 25 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 8d91edd7b2..7d567b223d 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -5570,7 +5570,11 @@ fn ifExpr( }; } else .{ .src = if_full.ast.then_expr, - .result = .none, + .result = switch (rl) { + // Explicitly store void to ptr result loc if there is no else branch + .ptr, .block_ptr => try rvalue(&else_scope, rl, .void_value, node), + else => .none, + }, }; const break_tag: Zir.Inst.Tag = if (parent_gz.force_comptime) .break_inline else .@"break"; diff --git a/test/cases/compile_errors/missing_else_clause.zig b/test/cases/compile_errors/missing_else_clause.zig index 716721bdea..2e5fe9318f 100644 --- a/test/cases/compile_errors/missing_else_clause.zig +++ b/test/cases/compile_errors/missing_else_clause.zig @@ -6,11 +6,32 @@ fn g(b: bool) void { const y = if (b) h: { break :h @as(i32, 1); }; _ = y; } -export fn entry() void { f(true); g(true); } - +fn h() void { + // https://github.com/ziglang/zig/issues/12743 + const T = struct { oh_no: *u32 }; + var x: T = if (false) {}; + _ = x; +} +fn k(b: bool) void { + // block_ptr case + const T = struct { oh_no: u32 }; + var x = if (b) blk: { + break :blk if (false) T{ .oh_no = 2 }; + } else T{ .oh_no = 1 }; + _ = x; +} +export fn entry() void { + f(true); + g(true); + h(); + k(true); +} // error // backend=stage2 // target=native // // :2:21: error: incompatible types: 'i32' and 'void' // :6:15: error: incompatible types: 'i32' and 'void' +// :12:16: error: expected type 'tmp.h.T', found 'void' +// :11:15: note: struct declared here +// :18:9: error: incompatible types: 'void' and 'tmp.k.T' |
