Skip to content

branching type resolution doesn't exclude noreturn and other coercible values #3210

@Techatrix

Description

@Techatrix

Zig Version

0.17.0-dev.292+fc1c83a36

ZLS Version

0.17.0-dev.44+8da87d4f

Client / Code Editor / Extensions

VSCodium (1.116.0) with ziglang.vscode-zig (0.6.18)

Steps to Reproduce and Observed Behavior

const S = struct {
    alpha: u32,
};
/// a value that ZLS cannot resolve
const unknown = unknown;

// good
const A = switch (unknown) {
    1 => S,
    else => unknown,
};

// bad
const B = switch (unknown) {
    1 => S,
    else => unreachable,
};

// bad
const C = switch (unknown) {
    1 => S,
    else => undefined,
};

// kind of works. Hover indicates that it isn't cleanly resolve to just `S`
const D = switch (unknown) {
    1 => S,
    else => @compileError(""),
};

Expected Behavior

The else branch of the switch cases should be ignored in all examples so that A, B, C, D all resolve to S.

Attach ZLS log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions