Skip to content

Commit 69803cb

Browse files
Vexumatu3ba
authored andcommitted
Sema: fix condition for omitting comptime arg from function type
Closes ziglang#14164
1 parent 99bfb4d commit 69803cb

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Sema.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9005,7 +9005,7 @@ fn zirParam(
90059005
else => |e| return e,
90069006
} or comptime_syntax;
90079007
if (sema.inst_map.get(inst)) |arg| {
9008-
if (is_comptime) {
9008+
if (is_comptime and sema.preallocated_new_func != null) {
90099009
// We have a comptime value for this parameter so it should be elided from the
90109010
// function type of the function instruction in this block.
90119011
const coerced_arg = try sema.coerce(block, param_ty, arg, src);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pub fn sort(
2+
comptime T: type,
3+
items: []T,
4+
context: anytype,
5+
lessThan: *const fn (context: @TypeOf(context), lhs: T, rhs: T) u32,
6+
) void {
7+
_ = items;
8+
_ = lessThan;
9+
}
10+
fn foo(_: void, _: u8, _: u8) u32 {
11+
return 0;
12+
}
13+
pub export fn entry() void {
14+
var items = [_]u8{ 3, 5, 7, 2, 6, 9, 4 };
15+
sort(u8, &items, void, foo);
16+
}
17+
18+
// error
19+
// backend=llvm
20+
// target=native
21+
//
22+
// :15:28: error: expected type '*const fn(comptime type, u8, u8) u32', found '*const fn(void, u8, u8) u32'
23+
// :15:28: note: pointer type child 'fn(void, u8, u8) u32' cannot cast into pointer type child 'fn(comptime type, u8, u8) u32'
24+
// :15:28: note: non-generic function cannot cast into a generic function

0 commit comments

Comments
 (0)