You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 27, 2021. It is now read-only.
One thing I'd like to consider is if the pattern works at comptime. I know that the Random interface at least works at comptime. Does this proof of concept work at comptime?
(If not, is it something that can be improved in the compiler, and it will work fine? I'm willing to do that work if necessary)
The text was updated successfully, but these errors were encountered:
My current prototype of vtable.populate does a cast from fn (self: *T) K -> fn (self: *c_void) K when it has validated that this is "safe" (I'm not sure if a do all the right tests). I do this, as I have no way of generating a wrapper function at comptime that casts the *c_void -> *T and calls the actual function.
Sadly, this does not work at comptime:
/home/hejsil/repo/tm35-gen4/test.zig:36:45: error: expected type '*MemReader', found '*c_void'
return reader.vtable.read(reader.impl, buf);
^
/home/hejsil/repo/tm35-gen4/test.zig:70:34: note: called from here
const bytes = try reader.read(buf[0..]);
^
/home/hejsil/repo/tm35-gen4/test.zig:6:20: note: called from here
while (byte(reader)) |c| {
^
/home/hejsil/repo/tm35-gen4/test.zig:36:45: note: pointer type child 'c_void' cannot cast into pointer type child 'MemReader'
return reader.vtable.read(reader.impl, buf);
^
/home/hejsil/repo/tm35-gen4/test.zig:41:19: note: MemReader declared here
const MemReader = struct {
Seems like comptime sees through my cast of the function, but not the cast from *T -> *c_void.
One thing I'd like to consider is if the pattern works at comptime. I know that the Random interface at least works at comptime. Does this proof of concept work at comptime?
(If not, is it something that can be improved in the compiler, and it will work fine? I'm willing to do that work if necessary)
The text was updated successfully, but these errors were encountered: