From a7ca40b2817dbf3f2085141f32f20f431707391b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 28 Feb 2022 10:08:26 -0800 Subject: [PATCH] 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. --- src/Sema.zig | 19 ++++++++----------- test/behavior/cast.zig | 6 +++++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index ccea8377c8..56cc3b13bb 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -17783,21 +17783,18 @@ fn resolvePeerTypes( const chosen_child_ty = chosen_ty.childType(); const candidate_child_ty = candidate_ty.childType(); if (chosen_child_ty.zigTypeTag() == .Array and candidate_child_ty.zigTypeTag() == .Array) { - // If there is a sentinel, it must match - if (chosen_child_ty.sentinel()) |chosen_sentinel| { - if (candidate_child_ty.sentinel()) |candidate_sentinel| { - if (!chosen_sentinel.eql(candidate_sentinel, chosen_child_ty)) { - continue; - } - } else { - continue; - } - } - // If we can cerce the element types, then we can do this. const chosen_elem_ty = chosen_child_ty.elemType2(); const candidate_elem_ty = candidate_child_ty.elemType2(); if ((try sema.coerceInMemoryAllowed(block, candidate_elem_ty, chosen_elem_ty, false, target, src, src)) == .ok) { + // If there is a sentinel, it must match + if (chosen_child_ty.sentinel()) |chosen_sentinel| { + if (candidate_child_ty.sentinel()) |candidate_sentinel| { + if (!chosen_sentinel.eql(candidate_sentinel, chosen_elem_ty)) + continue; + } else continue; + } + chosen = candidate; chosen_i = candidate_i + 1; diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index 819739083b..4ce4faa375 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -655,7 +655,11 @@ test "peer cast *[N]T to [*]T" { } test "peer resolution of string literals" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO const S = struct { const E = enum { a, b, c, d };