diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-14 18:10:54 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-07-14 18:11:46 -0700 |
| commit | 04572f6e341e6ff19877d1ae3b79e3baa653e652 (patch) | |
| tree | 07b91717329efb36bd8c8bd266b047fff60692ff /test/behavior/if.zig | |
| parent | d7711ec9532d4c38bf1911f5c0ed2c813705ae15 (diff) | |
| download | zig-04572f6e341e6ff19877d1ae3b79e3baa653e652.tar.gz zig-04572f6e341e6ff19877d1ae3b79e3baa653e652.zip | |
Sema: fix coerceResultPtr
It did not handle properly when the dummy operand was a comptime_int; it
was crashing in coerce because comptime_int is supposed to be
comptime-known. So when calling coerceResultPtr, we pass the actual
operand, not a dummy operand, which means it will have the proper
comptime value when necessary.
Diffstat (limited to 'test/behavior/if.zig')
| -rw-r--r-- | test/behavior/if.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/behavior/if.zig b/test/behavior/if.zig index 7618363474..8117c1db3f 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -140,3 +140,19 @@ test "if-else expression with runtime condition result location is inferred opti const e = if (d) A{ .b = 15, .c = 30 } else null; try expect(e != null); } + +test "result location with inferred type ends up being pointer to comptime_int" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; + + var a: ?u32 = 1234; + var b: u32 = 2000; + var c = if (a) |d| blk: { + if (d < b) break :blk @as(u32, 1); + break :blk 0; + } else @as(u32, 0); + try expect(c == 1); +} |
