Skip to content

@errorCast on error unions should allow disjoint sets #17355

@andrewrk

Description

@andrewrk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions