authorgravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-02-28 10:08:26-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-28 16:27:16-05:00
loga7ca40b2817dbf3f2085141f32f20f431707391b
tree620ebeb2fa323da8f0b66d9ff638a96bbb9a4c77
parentd1a46548349a902c30057b3ba66ebad9bc25bdd2

stage2: sentinel comp during peer type resolution should use elem type

We were using the array type, not the element type. Also, we should do the sentinel comparison after we verify that the element types of both are compatible.

2 files changed, 13 insertions(+), 12 deletions(-)

src/Sema.zig+8-11
......@@ -17783,21 +17783,18 @@ fn resolvePeerTypes(
1778317783 const chosen_child_ty = chosen_ty.childType();
1778417784 const candidate_child_ty = candidate_ty.childType();
1778517785 if (chosen_child_ty.zigTypeTag() == .Array and candidate_child_ty.zigTypeTag() == .Array) {
17786 // If there is a sentinel, it must match
17787 if (chosen_child_ty.sentinel()) |chosen_sentinel| {
17788 if (candidate_child_ty.sentinel()) |candidate_sentinel| {
17789 if (!chosen_sentinel.eql(candidate_sentinel, chosen_child_ty)) {
17790 continue;
17791 }
17792 } else {
17793 continue;
17794 }
17795 }
17796
1779717786 // If we can cerce the element types, then we can do this.
1779817787 const chosen_elem_ty = chosen_child_ty.elemType2();
1779917788 const candidate_elem_ty = candidate_child_ty.elemType2();
1780017789 if ((try sema.coerceInMemoryAllowed(block, candidate_elem_ty, chosen_elem_ty, false, target, src, src)) == .ok) {
17790 // If there is a sentinel, it must match
17791 if (chosen_child_ty.sentinel()) |chosen_sentinel| {
17792 if (candidate_child_ty.sentinel()) |candidate_sentinel| {
17793 if (!chosen_sentinel.eql(candidate_sentinel, chosen_elem_ty))
17794 continue;
17795 } else continue;
17796 }
17797
1780117798 chosen = candidate;
1780217799 chosen_i = candidate_i + 1;
1780317800
test/behavior/cast.zig+5-1
......@@ -655,7 +655,11 @@ test "peer cast *[N]T to [*]T" {
655655}
656656
657657test "peer resolution of string literals" {
658 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
658 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
659 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
660 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
661 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
662 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
659663
660664 const S = struct {
661665 const E = enum { a, b, c, d };