aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-11-22 17:56:14 +0200
committerVeikka Tuominen <git@vexu.eu>2022-11-23 22:16:31 +0200
commit9f055e2eb0252d872c9111e60ef7c0802d91bea6 (patch)
treeeff808b42378164a030e946542af1660e5e1c6a1 /src/Sema.zig
parent8eea73fb922c1c7fab4b8bf1717588464691a66e (diff)
downloadzig-9f055e2eb0252d872c9111e60ef7c0802d91bea6.tar.gz
zig-9f055e2eb0252d872c9111e60ef7c0802d91bea6.zip
Sema: improve compile error for tuple coercion mismatch
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 7265207e9b..a756f8be81 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -24206,7 +24206,10 @@ fn coerceExtra(
inst_ty.childType().isAnonStruct() and
sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result))
{
- return sema.coerceAnonStructToStructPtrs(block, dest_ty, dest_ty_src, inst, inst_src);
+ return sema.coerceAnonStructToStructPtrs(block, dest_ty, dest_ty_src, inst, inst_src) catch |err| switch (err) {
+ error.NotCoercible => break :pointer,
+ else => |e| return e,
+ };
}
},
.Array => {
@@ -24519,12 +24522,15 @@ fn coerceExtra(
},
else => {},
},
- .Struct => {
+ .Struct => blk: {
if (inst == .empty_struct) {
return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src);
}
if (inst_ty.isTupleOrAnonStruct()) {
- return sema.coerceTupleToStruct(block, dest_ty, inst, inst_src);
+ return sema.coerceTupleToStruct(block, dest_ty, inst, inst_src) catch |err| switch (err) {
+ error.NotCoercible => break :blk,
+ else => |e| return e,
+ };
}
},
else => {},
@@ -27215,6 +27221,8 @@ fn coerceTupleToTuple(
const inst_ty = sema.typeOf(inst);
const inst_field_count = inst_ty.structFieldCount();
+ if (inst_field_count > dest_field_count) return error.NotCoercible;
+
var runtime_src: ?LazySrcLoc = null;
var field_i: u32 = 0;
while (field_i < inst_field_count) : (field_i += 1) {