authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-02 14:42:05-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:59-07:00
log6a15fc87ad62ec0509017c960f6983ce1493c31d
tree4f343a0c509f7d86b533ef31b19a303b9632136d
parentad54f47b95a2295e0c199decb5ff10c572317a22

Sema: handle generic types when coercing functions in memory

This used to be handled by `Type.eql`, but that is now a single comparison.

1 files changed, 28 insertions(+), 20 deletions(-)

src/Sema.zig+28-20
...@@ -27498,17 +27498,20 @@ fn coerceInMemoryAllowedFns(...@@ -27498,17 +27498,20 @@ fn coerceInMemoryAllowedFns(
27498 } };27498 } };
27499 }27499 }
2750027500
27501 if (src_info.return_type != .noreturn_type) {27501 switch (src_info.return_type) {
27502 const dest_return_type = dest_info.return_type.toType();27502 .noreturn_type, .generic_poison_type => {},
27503 const src_return_type = src_info.return_type.toType();27503 else => {
27504 const rt = try sema.coerceInMemoryAllowed(block, dest_return_type, src_return_type, false, target, dest_src, src_src);27504 const dest_return_type = dest_info.return_type.toType();
27505 if (rt != .ok) {27505 const src_return_type = src_info.return_type.toType();
27506 return InMemoryCoercionResult{ .fn_return_type = .{27506 const rt = try sema.coerceInMemoryAllowed(block, dest_return_type, src_return_type, false, target, dest_src, src_src);
27507 .child = try rt.dupe(sema.arena),27507 if (rt != .ok) {
27508 .actual = dest_return_type,27508 return InMemoryCoercionResult{ .fn_return_type = .{
27509 .wanted = src_return_type,27509 .child = try rt.dupe(sema.arena),
27510 } };27510 .actual = dest_return_type,
27511 }27511 .wanted = src_return_type,
27512 } };
27513 }
27514 },
27512 }27515 }
27513 }27516 }
2751427517
...@@ -27548,15 +27551,20 @@ fn coerceInMemoryAllowedFns(...@@ -27548,15 +27551,20 @@ fn coerceInMemoryAllowedFns(
27548 } };27551 } };
27549 }27552 }
2755027553
27551 // Note: Cast direction is reversed here.27554 switch (src_param_ty.toIntern()) {
27552 const param = try sema.coerceInMemoryAllowed(block, src_param_ty, dest_param_ty, false, target, dest_src, src_src);27555 .generic_poison_type => {},
27553 if (param != .ok) {27556 else => {
27554 return InMemoryCoercionResult{ .fn_param = .{27557 // Note: Cast direction is reversed here.
27555 .child = try param.dupe(sema.arena),27558 const param = try sema.coerceInMemoryAllowed(block, src_param_ty, dest_param_ty, false, target, dest_src, src_src);
27556 .actual = src_param_ty,27559 if (param != .ok) {
27557 .wanted = dest_param_ty,27560 return InMemoryCoercionResult{ .fn_param = .{
27558 .index = param_i,27561 .child = try param.dupe(sema.arena),
27559 } };27562 .actual = src_param_ty,
27563 .wanted = dest_param_ty,
27564 .index = param_i,
27565 } };
27566 }
27567 },
27560 }27568 }
27561 }27569 }
2756227570