diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-07-14 16:48:44 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-07-14 16:48:44 -0700 |
| commit | 667ad9250f7250670778beedcebc45f5c0284446 (patch) | |
| tree | 76ac3d73766d13be52afa570111e4071d8d19cf9 /test/behavior/if.zig | |
| parent | 1653a9b2597c66cbcc88ea75d8a4b88c163584a5 (diff) | |
| download | zig-667ad9250f7250670778beedcebc45f5c0284446.tar.gz zig-667ad9250f7250670778beedcebc45f5c0284446.zip | |
Sema: fix coerce_result_ptr in case of inferred result type
Previously, the logic for analyzing coerce_result_ptr would generate
invalid bitcast instructions which did not include coercion logic, such
as optional wrapping, resulting in miscompilations.
Now, the logic of resolve_inferred_alloc goes back over all the
placeholders inserted by coerce_result_ptr, and replaces them with logic
doing the proper coercions.
Closes #12045
Diffstat (limited to 'test/behavior/if.zig')
| -rw-r--r-- | test/behavior/if.zig | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/behavior/if.zig b/test/behavior/if.zig index a78bf74502..7618363474 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -128,3 +128,15 @@ test "if peer expressions inferred optional type" { try expect(left.? == 98); try expect(right.? == 99); } + +test "if-else expression with runtime condition result location is inferred optional" { + 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; + + const A = struct { b: u64, c: u64 }; + var d: bool = true; + const e = if (d) A{ .b = 15, .c = 30 } else null; + try expect(e != null); +} |
