mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 14:55:25 +00:00
Sema: implement peer type resolution of function pointers and function bodies
Closes #13438
This commit is contained in:
parent
e6b3cb5043
commit
799a558e39
12
src/Sema.zig
12
src/Sema.zig
@ -28769,6 +28769,13 @@ fn resolvePeerTypes(
|
||||
}
|
||||
}
|
||||
},
|
||||
.Fn => {
|
||||
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)) {
|
||||
chosen = candidate;
|
||||
chosen_i = candidate_i + 1;
|
||||
continue;
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
},
|
||||
@ -28799,6 +28806,11 @@ fn resolvePeerTypes(
|
||||
.Vector => continue,
|
||||
else => {},
|
||||
},
|
||||
.Fn => if (chosen_ty.isSinglePointer() and chosen_ty.isConstPtr() and chosen_ty.childType().zigTypeTag() == .Fn) {
|
||||
if (.ok == try sema.coerceInMemoryAllowedFns(block, chosen_ty.childType(), candidate_ty, target, src, src)) {
|
||||
continue;
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
|
||||
@ -1419,3 +1419,13 @@ test "floatToInt to zero-bit int" {
|
||||
var a: f32 = 0.0;
|
||||
comptime try std.testing.expect(@floatToInt(u0, a) == 0);
|
||||
}
|
||||
|
||||
test "peer type resolution of function pointer and function body" {
|
||||
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
|
||||
|
||||
const T = fn () u32;
|
||||
const a: T = undefined;
|
||||
const b: *const T = undefined;
|
||||
try expect(@TypeOf(a, b) == *const fn () u32);
|
||||
try expect(@TypeOf(b, a) == *const fn () u32);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user