Skip to content

@errorCast on error unions should allow disjoint sets #17355

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

Closed
andrewrk opened this issue Oct 1, 2023 · 0 comments · Fixed by #17368
Closed

@errorCast on error unions should allow disjoint sets #17355

andrewrk opened this issue Oct 1, 2023 · 0 comments · Fixed by #17368
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Oct 1, 2023

Zig Version

0.12.0-dev.705+af40bce08

Steps to Reproduce and Observed Behavior

const std = @import("std");

test {
    const bar: error{}!i32 = @errorCast(foo());
    std.testing.expect((try bar) == 1234);
}

fn foo() anyerror!i32 {
    return 1234;
}
$ stage4/bin/zig test test3.zig 
test3.zig:4:30: error: error sets 'anyerror' and 'error{}' have no common errors
    const bar: error{}!i32 = @errorCast(foo());
                             ^~~~~~~~~~~~~~~~~

Expected Behavior

Test passed. All the logic for disjoint sets should be skipped when casting error unions.

However, there should be a safety check which would be triggered in the above example if foo is changed to return an error. In order to close this issue, an additional runtime safety test is needed to cover this.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Oct 1, 2023
@andrewrk andrewrk added this to the 0.12.0 milestone Oct 1, 2023
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant