authorgravatar for will.lillis24@gmail.comWill Lillis <will.lillis24@gmail.com> 2024-07-20 02:31:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-21 00:10:36-07:00
log18d412ab2fb7bda92f7bfbdf732849bbcd066c33
tree3363867ffee39f01401cd130f82f108d087ec62e
parent9b292c094909e51718c1d37dbeb859674dd98c8a

fix: remove misleading error note for failed array coercions


2 files changed, 22 insertions(+), 7 deletions(-)

src/Sema.zig+11-7
......@@ -30279,7 +30279,7 @@ pub fn coerceInMemoryAllowed(
3027930279
3028030280 if ((src_info.signedness == dest_info.signedness and dest_info.bits < src_info.bits) or
3028130281 // small enough unsigned ints can get casted to large enough signed ints
30282 (dest_info.signedness == .signed and (src_info.signedness == .unsigned or dest_info.bits <= src_info.bits)) or
30282 (dest_info.signedness == .signed and src_info.signedness == .unsigned and dest_info.bits <= src_info.bits) or
3028330283 (dest_info.signedness == .unsigned and src_info.signedness == .signed))
3028430284 {
3028530285 return InMemoryCoercionResult{ .int_not_coercible = .{
......@@ -30360,12 +30360,16 @@ pub fn coerceInMemoryAllowed(
3036030360 }
3036130361
3036230362 const child = try sema.coerceInMemoryAllowed(block, dest_info.elem_type, src_info.elem_type, dest_is_mut, target, dest_src, src_src, null);
30363 if (child != .ok) {
30364 return InMemoryCoercionResult{ .array_elem = .{
30365 .child = try child.dupe(sema.arena),
30366 .actual = src_info.elem_type,
30367 .wanted = dest_info.elem_type,
30368 } };
30363 switch (child) {
30364 .ok => {},
30365 .no_match => return child,
30366 else => {
30367 return InMemoryCoercionResult{ .array_elem = .{
30368 .child = try child.dupe(sema.arena),
30369 .actual = src_info.elem_type,
30370 .wanted = dest_info.elem_type,
30371 } };
30372 },
3036930373 }
3037030374 const ok_sent = (dest_info.sentinel == null and src_info.sentinel == null) or
3037130375 (src_info.sentinel != null and
test/cases/compile_errors/invalid_array_assignment_with_valid_elems.zig created+11
......@@ -0,0 +1,11 @@
1export fn a() void {
2 const x = [_]u16{ 1, 2, 3 };
3 const y: [3]i32 = x;
4 _ = y;
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// 3:23: error: expected type '[3]i32', found '[3]u16'