| author | |
| committer | |
| log | 799a558e393d1c8286e8faec2bf8930138d8b1f4 |
| tree | 50beaa01c84a45fcf4162b80a62eaeda36cb4fe3 |
| parent | e6b3cb5043b189fab6417df4a6921728ea174c8f |
Closes #134382 files changed, 22 insertions(+), 0 deletions(-)
src/Sema.zig+12| ... | ... | @@ -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 | 28779 | else => {}, |
| 28773 | 28780 | } |
| 28774 | 28781 | }, |
| ... | ... | @@ -28799,6 +28806,11 @@ fn resolvePeerTypes( |
| 28799 | 28806 | .Vector => continue, |
| 28800 | 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 | 28814 | else => {}, |
| 28803 | 28815 | } |
| 28804 | 28816 |
test/behavior/cast.zig+10| ... | ... | @@ -1419,3 +1419,13 @@ test "floatToInt to zero-bit int" { |
| 1419 | 1419 | var a: f32 = 0.0; |
| 1420 | 1420 | comptime try std.testing.expect(@floatToInt(u0, a) == 0); |
| 1421 | 1421 | } |
| 1422 | ||
| 1423 | test "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 | } |