Skip to content

Disallow error union with error set payload, E!E #7913

@Vexu

Description

@Vexu

The type makes no sense and cannot be created:

test {
    const E = error{Foo};


    // error: expected type 'E', found 'error{Bar}'
    var a: E!anyerror = error.Bar;


    // error: expected type 'E', found 'anyerror'
    var b: anyerror = error.Bar;
    var a: E!anyerror = b;


    // panic: invalid error code
    var b: anyerror = error.Bar;
    var a: E!anyerror = @errSetCast(E, b);


    // panic: reached unreachable code
    @setRuntimeSafety(false);
    var b: anyerror = error.Bar;
    var a: E!anyerror = @errSetCast(E, b);
    var discard = a catch @import("std").debug.assert(false);
}

// This does work but hardly justifies its existence.
const E = error{Foo};
const E2 = error{Bar};
const S = struct { payload: E2, err: u16 };
test {
    var a: E!E2 = undefined;
    a = @bitCast(E!E2, S{ .payload = E2.Bar, .err = 0 });
    var foo = a catch unreachable;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions