Skip to content

@errSetCast refuses to accept an error union operand #17343

@andrewrk

Description

@andrewrk

Zig Version

0.12.0-dev.695+303181901

Steps to Reproduce and Observed Behavior

const std = @import("std");

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

fn foo() anyerror!i32 {
    return 1234;
}
$ stage4/bin/zig test test.zig 
test.zig:4:33: error: expected error set type, found 'i32'
    const bar: error{Bad}!i32 = @errSetCast(foo());
                                ^~~~~~~~~~~~~~~~~~

Expected Behavior

Test passed.

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