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 a fn with empty error set return value when a function with an error is expected should be a compile error #762

andrewrk opened this Issue Feb 9, 2018 · 0 comments


None yet
1 participant

andrewrk commented Feb 9, 2018


export fn entry() void {

fn foo(f: fn()error!void) void {
    const x = f();

fn bar() (error{}!void) {
[nix-shell:~/dev/zig/build]$ ./zig build-obj test.zig 
Call parameter type does not match function signature!
void (%StackTrace*)* @bar
 i16 (%StackTrace*)*  call fastcc void @foo(void (%StackTrace*)* @bar), !dbg !777
LLVM ERROR: Broken module found, compilation aborted!

Although implicitly casting a error{}!void to error!void is sound, it doesn't work as a return value, because the function pointer expects there to be an actual integer return type, and our optimization to using void does not work because it should return 0.

Actually now that I think of it, I think we should just change this optimization to using void, to not do that, and instead it should still be an integer.

@andrewrk andrewrk added the bug label Feb 9, 2018

@andrewrk andrewrk added this to the 0.2.0 milestone Feb 9, 2018

@andrewrk andrewrk modified the milestones: 0.2.0, 0.3.0 Mar 14, 2018

@Hejsil Hejsil closed this in 3178528 Apr 28, 2018

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