diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-06-29 14:26:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-29 14:26:23 -0400 |
| commit | 98681b2da070755c29065d21d2ffb17be37d9619 (patch) | |
| tree | cf9592ac47d5fd6d10557be65fb9d38c624728ee /test/behavior | |
| parent | 7cc417644862a9b9523545f4455da7722afc8209 (diff) | |
| parent | c3ae909e935f1548408f2e400464370ee02b7e82 (diff) | |
| download | zig-98681b2da070755c29065d21d2ffb17be37d9619.tar.gz zig-98681b2da070755c29065d21d2ffb17be37d9619.zip | |
Merge pull request #11958 from ziglang/store-to-inferred-ptr
stage2: fix miscompilations for peer expressions any time they needed coercions to runtime types
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/basic.zig | 12 | ||||
| -rw-r--r-- | test/behavior/cast.zig | 2 | ||||
| -rw-r--r-- | test/behavior/error.zig | 2 | ||||
| -rw-r--r-- | test/behavior/if.zig | 17 |
4 files changed, 20 insertions, 13 deletions
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index d288d35787..8241579229 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -928,18 +928,6 @@ test "try in labeled block doesn't cast to wrong type" { _ = s; } -test "comptime int in switch in catch is casted to correct inferred type" { - if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; - - var a: error{ A, B }!u64 = 0; - var b = a catch |err| switch (err) { - error.A => 0, - else => unreachable, - }; - _ = b; -} - test "vector initialized with array init syntax has proper type" { comptime { const actual = -@Vector(4, i32){ 1, 2, 3, 4 }; diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index c980de8e8a..7064b5abdc 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -812,6 +812,7 @@ test "peer type resolution: error union after non-error" { } test "peer cast *[0]T to E![]const T" { + 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; // TODO if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO @@ -826,6 +827,7 @@ test "peer cast *[0]T to E![]const T" { } test "peer cast *[0]T to []const T" { + 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; // TODO if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO diff --git a/test/behavior/error.zig b/test/behavior/error.zig index c32ca6f6a1..0e3767a4ca 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -709,7 +709,7 @@ test "simple else prong allowed even when all errors handled" { } }; var value = S.foo() catch |err| switch (err) { - error.Foo => 255, + error.Foo => @as(u8, 255), else => |e| return e, }; try expect(value == 255); diff --git a/test/behavior/if.zig b/test/behavior/if.zig index d59a974ce4..a78bf74502 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -111,3 +111,20 @@ test "if prongs cast to expected type instead of peer type resolution" { try S.doTheTest(false); comptime try S.doTheTest(false); } + +test "if peer expressions inferred optional type" { + 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; + + var self: []const u8 = "abcdef"; + var index: usize = 0; + var left_index = (index << 1) + 1; + var right_index = left_index + 1; + var left = if (left_index < self.len) self[left_index] else null; + var right = if (right_index < self.len) self[right_index] else null; + try expect(left_index < self.len); + try expect(right_index < self.len); + try expect(left.? == 98); + try expect(right.? == 99); +} |
