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(
2420624206 inst_ty.childType().isAnonStruct() and
2420724207 sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result))
2420824208 {
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 };
2421024213 }
2421124214 },
2421224215 .Array => {
......@@ -24519,12 +24522,15 @@ fn coerceExtra(
2451924522 },
2452024523 else => {},
2452124524 },
24522 .Struct => {
24525 .Struct => blk: {
2452324526 if (inst == .empty_struct) {
2452424527 return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src);
2452524528 }
2452624529 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 };
2452824534 }
2452924535 },
2453024536 else => {},
......@@ -27215,6 +27221,8 @@ fn coerceTupleToTuple(
2721527221
2721627222 const inst_ty = sema.typeOf(inst);
2721727223 const inst_field_count = inst_ty.structFieldCount();
27224 if (inst_field_count > dest_field_count) return error.NotCoercible;
27225
2721827226 var runtime_src: ?LazySrcLoc = null;
2721927227 var field_i: u32 = 0;
2722027228 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 {
77// backend=stage2
88// target=native
99//
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}'