Skip to content
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

Segmentation fault when returning var #829

Closed
AndreaOrru opened this issue Mar 13, 2018 · 3 comments · Fixed by #5846
Closed

Segmentation fault when returning var #829

AndreaOrru opened this issue Mar 13, 2018 · 3 comments · Fixed by #5846
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@AndreaOrru
Copy link
Contributor

AndreaOrru commented Mar 13, 2018

Minimal example:

fn metafoo(comptime function: var) var {
    return function;
}

fn foo() void {}

pub fn main() void {
    _ = metafoo(foo);
}

For context, specifying the return value explicitly works:

fn metafoo(comptime function: var) @typeOf(function) {
    return function;
}
@andrewrk
Copy link
Member

this is #447

but I'll leave this open, at least I can make it print a compile error instead of segfaulting.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Mar 13, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Mar 13, 2018
@ghost
Copy link

ghost commented Sep 6, 2018

This is still crashing in some cases

First case: gives compile error (good)

fn badFunction() var { return 0; }
test "" { _ = badFunction(u32); }

Output:

/home/dbandstra/oxid/test.zig:1:1: error: TODO implement inferred return types https://github.com/ziglang/zig/issues/447
fn badFunction() var {
^
The following command exited with error code 1 [...]

Second case: crashes with message

fn badFunction(comptime T: type) var { return 0; }
test "" { _ = badFunction(u32); }

Output:

TODO implement inferred return types https://github.com/ziglang/zig/issues/447
The following command exited with error code 1 [...]

Third case: crashes with no message

fn badFunction(comptime T: type) var { return 0; }
test "" { _ = comptime badFunction(u32); }

Output:

The following command exited with error code 1 [...]

@andrewrk andrewrk reopened this Sep 7, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Sep 11, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Apr 3, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 27, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Dec 9, 2019
@bb010g
Copy link

bb010g commented Jul 10, 2020

#5834 is a duplicate of this. (Thanks, @Snektron.)

On the side, Godbolt reported this as error code 255, not error code 1. Not sure if that's how it tries to report segfaults?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants