Fix closure types not working with void captures
This commit is contained in:
parent
da7d9cfcc0
commit
989de70461
|
@ -48,20 +48,20 @@ pub fn BiFunction(comptime captures_size: usize, comptime A: type,
|
|||
@compileError("`captures` must be smaller than or equal to " ++
|
||||
std.fmt.comptimePrint("{d}", .{captures_size}) ++ " bytes");
|
||||
|
||||
const captures_align = @alignOf(Captures);
|
||||
|
||||
var function = Self{
|
||||
.context = undefined,
|
||||
|
||||
.applyErased = struct {
|
||||
fn do(erased: *anyopaque, a: A, b: B) Out {
|
||||
return call(@ptrCast(*Captures, @alignCast(
|
||||
captures_align, erased)).*, a, b);
|
||||
fn applyErased(erased: *anyopaque, a: A, b: B) Out {
|
||||
return call(if (Captures == void) {} else @ptrCast(*Captures,
|
||||
@alignCast(@alignOf(Captures), erased)).*, a, b);
|
||||
}
|
||||
}.do,
|
||||
}.applyErased,
|
||||
};
|
||||
|
||||
@ptrCast(*Captures, @alignCast(captures_align, &function.context)).* = captures;
|
||||
if (captures != {}) {
|
||||
@ptrCast(*Captures, @alignCast(@alignOf(Captures), &function.context)).* = captures;
|
||||
}
|
||||
|
||||
return function;
|
||||
}
|
||||
|
@ -108,11 +108,11 @@ pub fn Function(comptime captures_size: usize, comptime In: type, comptime Out:
|
|||
.context = undefined,
|
||||
|
||||
.applyErased = struct {
|
||||
fn do(erased: *anyopaque, input: In) Out {
|
||||
return call(@ptrCast(*Captures, @alignCast(
|
||||
captures_align, erased)).*, input);
|
||||
fn applyErased(erased: *anyopaque, input: In) Out {
|
||||
return call(if (Captures == void) {} else @ptrCast(*Captures,
|
||||
@alignCast(@alignOf(Captures), erased)).*, input);
|
||||
}
|
||||
}.do,
|
||||
}.applyErased,
|
||||
};
|
||||
|
||||
@ptrCast(*Captures, @alignCast(captures_align, &function.context)).* = captures;
|
||||
|
|
Loading…
Reference in New Issue