authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-04 17:10:23+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-04 23:13:49+02:00
log799a558e393d1c8286e8faec2bf8930138d8b1f4
tree50beaa01c84a45fcf4162b80a62eaeda36cb4fe3
parente6b3cb5043b189fab6417df4a6921728ea174c8f

Sema: implement peer type resolution of function pointers and function bodies

Closes #13438

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

src/Sema.zig+12
...@@ -28769,6 +28769,13 @@ fn resolvePeerTypes(...@@ -28769,6 +28769,13 @@ fn resolvePeerTypes(
28769 }28769 }
28770 }28770 }
28771 },28771 },
28772 .Fn => {
28773 if (!cand_info.mutable and cand_info.pointee_type.zigTypeTag() == .Fn and .ok == try sema.coerceInMemoryAllowedFns(block, chosen_ty, cand_info.pointee_type, target, src, src)) {
28774 chosen = candidate;
28775 chosen_i = candidate_i + 1;
28776 continue;
28777 }
28778 },
28772 else => {},28779 else => {},
28773 }28780 }
28774 },28781 },
...@@ -28799,6 +28806,11 @@ fn resolvePeerTypes(...@@ -28799,6 +28806,11 @@ fn resolvePeerTypes(
28799 .Vector => continue,28806 .Vector => continue,
28800 else => {},28807 else => {},
28801 },28808 },
28809 .Fn => if (chosen_ty.isSinglePointer() and chosen_ty.isConstPtr() and chosen_ty.childType().zigTypeTag() == .Fn) {
28810 if (.ok == try sema.coerceInMemoryAllowedFns(block, chosen_ty.childType(), candidate_ty, target, src, src)) {
28811 continue;
28812 }
28813 },
28802 else => {},28814 else => {},
28803 }28815 }
2880428816
test/behavior/cast.zig+10
...@@ -1419,3 +1419,13 @@ test "floatToInt to zero-bit int" {...@@ -1419,3 +1419,13 @@ test "floatToInt to zero-bit int" {
1419 var a: f32 = 0.0;1419 var a: f32 = 0.0;
1420 comptime try std.testing.expect(@floatToInt(u0, a) == 0);1420 comptime try std.testing.expect(@floatToInt(u0, a) == 0);
1421}1421}
1422
1423test "peer type resolution of function pointer and function body" {
1424 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
1425
1426 const T = fn () u32;
1427 const a: T = undefined;
1428 const b: *const T = undefined;
1429 try expect(@TypeOf(a, b) == *const fn () u32);
1430 try expect(@TypeOf(b, a) == *const fn () u32);
1431}