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

Compiler SIGKILL/crash when returning from a function with the return type noreturn #7928

Closed
ghost opened this issue Feb 1, 2021 · 3 comments
Milestone

Comments

@ghost
Copy link

ghost commented Feb 1, 2021

The following code caused the compiler to send a SIGKILL to itself on my computer, and crashed the compiler on godbolt.org:

fn a() !noreturn {
    return;
}

pub fn main() void {
    var b = a() catch unreachable;
}

Of course, the above program is ill-formed, yet the compiler accepts it.

Moreover, using noreturn in an error union with an inferred error set should be illegal.

@rohlem
Copy link
Contributor

rohlem commented Feb 1, 2021

Probably related to #3263 .

Moreover, using noreturn in an error union should be illegal.

e!noreturn has real uses (f.e. here), it means the function can either return an error value from e, or never return to the caller.
Constructing an error union value by (compatible) error value always works, and doesn't interact with the payload type in any way.
The only illegal behaviour in this code seems to me that the function returns not an error, but trying to instantiate the type noreturn. (That said, quite likely that !noreturn is majorly broken in the compiler though.)

@ghost
Copy link
Author

ghost commented Feb 1, 2021

Probably related to #3263 .

Moreover, using noreturn in an error union should be illegal.

e!noreturn has real uses (f.e. here), it means the function can either return an error value from e, or never return to the caller.
Constructing an error union value by (compatible) error value always works, and doesn't interact with the payload type in any way.
The only illegal behaviour in this code seems to me that the function returns not an error, but trying to instantiate the type noreturn. (That said, quite likely that !noreturn is majorly broken in the compiler though.)

IMO !noreturn should be disallowed. If a function does not return under normal conditions, the abnormal conditions should be clear.

@ghost
Copy link
Author

ghost commented Feb 2, 2021

This is almost definitely a duplicate of #3263, and certainly a duplicate of #4698, which is itself a duplicate of #3263.

@ghost ghost closed this as completed Feb 2, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone Jun 4, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants