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(
2876928769 }
2877028770 }
2877128771 },
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 },
2877228779 else => {},
2877328780 }
2877428781 },
......@@ -28799,6 +28806,11 @@ fn resolvePeerTypes(
2879928806 .Vector => continue,
2880028807 else => {},
2880128808 },
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 },
2880228814 else => {},
2880328815 }
2880428816
test/behavior/cast.zig+10
......@@ -1419,3 +1419,13 @@ test "floatToInt to zero-bit int" {
14191419 var a: f32 = 0.0;
14201420 comptime try std.testing.expect(@floatToInt(u0, a) == 0);
14211421}
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}