Skip to content

allow implicit cast from union to its tag type  #642

@andrewrk

Description

@andrewrk
  • implicit cast from tag type of union with comptime known value to union if the payload
    for that field is void
  • implicit cast from union with comptime known value to tag type if the payload for that field is void
const Letter = enum { A, B, C };
const Value = union(Letter) {
    A: i32,
    B,
    C,
};

fn foo(x: Letter) {

}

test "aoeu" {
    var x: Value = Letter.B;
    foo(x);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.enhancementSolving this issue will likely involve adding new logic or components to the codebase.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