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

Implicit error types crash stage1 #2203

Closed
shawnl opened this issue Apr 6, 2019 · 3 comments
Closed

Implicit error types crash stage1 #2203

shawnl opened this issue Apr 6, 2019 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@shawnl
Copy link
Contributor

shawnl commented Apr 6, 2019

If you use an implicit error in a switch

catch |err| switch (err) {
.MyError =>
}

it will crash with

zig: ../src/ir.cpp:21037: IrInstruction* ir_analyze_instruction_check_switch_prongs(IrAnalyze*, IrInstructionCheckSwitchProngs*): Assertion `start_value->value.type->id == ZigTypeIdErrorSet' failed.

Glad I finially figured out what the bug was...so I can work around it and continue hacking.

@andrewrk andrewrk added this to the 0.5.0 milestone Apr 7, 2019
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Apr 7, 2019
hryx added a commit to hryx/zig that referenced this issue May 8, 2019
The ideal way to do this is to switch on the error type,
but there is a bug in the IR analyze phase described here:
ziglang#2203
@LemonBoy
Copy link
Contributor

LemonBoy commented May 8, 2019

The parser recognizes .MyError as a ZigTypeIdEnumLiteral, we can either reject this with a proper error instead of an assertion or make it work by teaching the compiler how to cast it to a ZigTypeIdErrorSet.

@shawnl
Copy link
Contributor Author

shawnl commented May 9, 2019

or make it work by teaching the compiler how to cast it to a ZigTypeIdErrorSet.

+1

@andrewrk
Copy link
Member

andrewrk commented May 9, 2019

It's a compile error, because:

const Error = error {Bad};
const Enum = enum {Bad};
fn foo() Error!Enum {
    return .Bad; // what does this do?
}

Feel free to open a proposal to discuss more.

@andrewrk andrewrk mentioned this issue May 9, 2019
5 tasks
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

No branches or pull requests

3 participants