authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-22 17:56:14+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-23 22:16:31+02:00
log9f055e2eb0252d872c9111e60ef7c0802d91bea6
treeeff808b42378164a030e946542af1660e5e1c6a1
parent8eea73fb922c1c7fab4b8bf1717588464691a66e

Sema: improve compile error for tuple coercion mismatch


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

src/Sema.zig+11-3
...@@ -24206,7 +24206,10 @@ fn coerceExtra(...@@ -24206,7 +24206,10 @@ fn coerceExtra(
24206 inst_ty.childType().isAnonStruct() and24206 inst_ty.childType().isAnonStruct() and
24207 sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result))24207 sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result))
24208 {24208 {
24209 return sema.coerceAnonStructToStructPtrs(block, dest_ty, dest_ty_src, inst, inst_src);24209 return sema.coerceAnonStructToStructPtrs(block, dest_ty, dest_ty_src, inst, inst_src) catch |err| switch (err) {
24210 error.NotCoercible => break :pointer,
24211 else => |e| return e,
24212 };
24210 }24213 }
24211 },24214 },
24212 .Array => {24215 .Array => {
...@@ -24519,12 +24522,15 @@ fn coerceExtra(...@@ -24519,12 +24522,15 @@ fn coerceExtra(
24519 },24522 },
24520 else => {},24523 else => {},
24521 },24524 },
24522 .Struct => {24525 .Struct => blk: {
24523 if (inst == .empty_struct) {24526 if (inst == .empty_struct) {
24524 return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src);24527 return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src);
24525 }24528 }
24526 if (inst_ty.isTupleOrAnonStruct()) {24529 if (inst_ty.isTupleOrAnonStruct()) {
24527 return sema.coerceTupleToStruct(block, dest_ty, inst, inst_src);24530 return sema.coerceTupleToStruct(block, dest_ty, inst, inst_src) catch |err| switch (err) {
24531 error.NotCoercible => break :blk,
24532 else => |e| return e,
24533 };
24528 }24534 }
24529 },24535 },
24530 else => {},24536 else => {},
...@@ -27215,6 +27221,8 @@ fn coerceTupleToTuple(...@@ -27215,6 +27221,8 @@ fn coerceTupleToTuple(
2721527221
27216 const inst_ty = sema.typeOf(inst);27222 const inst_ty = sema.typeOf(inst);
27217 const inst_field_count = inst_ty.structFieldCount();27223 const inst_field_count = inst_ty.structFieldCount();
27224 if (inst_field_count > dest_field_count) return error.NotCoercible;
27225
27218 var runtime_src: ?LazySrcLoc = null;27226 var runtime_src: ?LazySrcLoc = null;
27219 var field_i: u32 = 0;27227 var field_i: u32 = 0;
27220 while (field_i < inst_field_count) : (field_i += 1) {27228 while (field_i < inst_field_count) : (field_i += 1) {
test/cases/compile_errors/type_mismatch_with_tuple_concatenation.zig+1-1
...@@ -7,4 +7,4 @@ export fn entry() void {...@@ -7,4 +7,4 @@ export fn entry() void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :3:11: error: index '0' out of bounds of tuple '@TypeOf(.{})'10// :3:11: error: expected type '@TypeOf(.{})', found 'tuple{comptime comptime_int = 1, comptime comptime_int = 2, comptime comptime_int = 3}'