Skip to content

errdefer |err| uses the local errorset instead of the wrapping errorset #8697

Description

@fengb

This fails to compile. Seems like the compiler does not transfer the correct errorset into the errdefer handler:

fn foo(val: bool) !void {
    // error: expected type 'error{Truth}', found 'error{Justice}'
    errdefer |err| switch (err) {
        error.Truth => {},
        error.Justice => {},
    };

    if (val) {
        return error.Truth;
    } else {
        return error.Justice;
    }
}

Even more bizarrely, sometimes the errdefer receives an error union:

fn foo(val: bool) error{Truth,Justice}!void {
    // error: invalid switch target type 'error:1:19!void'
    errdefer |err| switch (err) {};
    return if (val) error.Truth else error.Justice;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions