diff --git a/src/Sema.zig b/src/Sema.zig index d1a558d15b..b41dd21b81 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -28340,8 +28340,16 @@ fn resolvePeerTypes( const candidate_ty_tag = try candidate_ty.zigTypeTagOrPoison(); const chosen_ty_tag = try chosen_ty.zigTypeTagOrPoison(); - if (candidate_ty.eql(chosen_ty, sema.mod)) + // If the candidate can coerce into our chosen type, we're done. + // If the chosen type can coerce into the candidate, use that. + if ((try sema.coerceInMemoryAllowed(block, chosen_ty, candidate_ty, false, target, src, src)) == .ok) { continue; + } + if ((try sema.coerceInMemoryAllowed(block, candidate_ty, chosen_ty, false, target, src, src)) == .ok) { + chosen = candidate; + chosen_i = candidate_i + 1; + continue; + } switch (candidate_ty_tag) { .NoReturn, .Undefined => continue, @@ -28741,17 +28749,6 @@ fn resolvePeerTypes( else => {}, } - // If the candidate can coerce into our chosen type, we're done. - // If the chosen type can coerce into the candidate, use that. - if ((try sema.coerceInMemoryAllowed(block, chosen_ty, candidate_ty, false, target, src, src)) == .ok) { - continue; - } - if ((try sema.coerceInMemoryAllowed(block, candidate_ty, chosen_ty, false, target, src, src)) == .ok) { - chosen = candidate; - chosen_i = candidate_i + 1; - continue; - } - // At this point, we hit a compile error. We need to recover // the source locations. const chosen_src = candidate_srcs.resolve( diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index cb76f86820..8473abc3ef 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -1444,3 +1444,10 @@ test "coerce between pointers of compatible differently-named floats" { f2.* += 1; try expect(f1 == @as(F, 12.34) + 1); } + +test "peer type resolution of const and non-const pointer to array" { + const a = @intToPtr(*[1024]u8, 42); + const b = @intToPtr(*const [1024]u8, 42); + try std.testing.expect(@TypeOf(a, b) == *const [1024]u8); + try std.testing.expect(a == b); +}