Skip to content

Switch branch of noreturn union field with mutable capture is incorrectly semantically analyzed #13655

Closed
@ifreund

Description

@ifreund

Zig Version

0.11.0-dev.168+b2ffe113d

Steps to Reproduce and Observed Behavior

This test should pass, but it fails due to the @compileError() being triggered.

test "mutable capture of noreturn union field" {
    const U = union(enum) {
        a: u32,
        b: noreturn,
    };
    var a = U{ .a = 1 };
    switch (a) {
        .a => {},
        .b => |*val| {
            _ = val;
            @compileError("Shouldn't be triggered");
        },
    }
}

Expected Behavior

The test should pass. Note that we have test coverage in place for immutable captures and the given test passes if |val| is used instead of |*val|.

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