New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing functions to c causes an assertion failure while compiling #659

Closed
cenomla opened this Issue Dec 18, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@cenomla

cenomla commented Dec 18, 2017

When a function is passed to c that has ?&void or ?&const void as one of the arguments it causes an assertion failure in the compiler:

zig: /home/cenomla/Workspace/zig/zig/src/analyze.cpp:432: TypeTableEntry* get_maybe_type(CodeGen*, TypeTableEntry*): Assertion 'child_type->type_def' failed.

If c_void is used in place of void then zig just crashes without an assertion.

@andrewrk andrewrk added the bug label Dec 18, 2017

@andrewrk andrewrk added this to the 0.2.0 milestone Dec 18, 2017

@andrewrk andrewrk closed this in 1cc450e Dec 19, 2017

@andrewrk

This comment has been minimized.

Show comment
Hide comment
@andrewrk

andrewrk Dec 19, 2017

Member

I fixed the assertion failure, and then added a compile error for using &void in a C function because you're supposed to use &c_void. This now works for me:

extern fn foo(ptr: extern fn(?&c_void));

export fn entry() {
    foo(bar);
}

extern fn bar(x: ?&c_void) {

}
zig build-obj test.zig

Let me know if you find another problematic test case.

Member

andrewrk commented Dec 19, 2017

I fixed the assertion failure, and then added a compile error for using &void in a C function because you're supposed to use &c_void. This now works for me:

extern fn foo(ptr: extern fn(?&c_void));

export fn entry() {
    foo(bar);
}

extern fn bar(x: ?&c_void) {

}
zig build-obj test.zig

Let me know if you find another problematic test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment