Skip to content

incorrect peer type resolution taking the address of catch |err| switch (err) #19881

@xdBronch

Description

@xdBronch

Zig Version

0.12

Steps to Reproduce and Observed Behavior

test {
    @compileLog(@TypeOf(&(try @as(anyerror!usize, 0))));
    @compileLog(@TypeOf(&(@as(anyerror!usize, 0) catch {})));
    @compileLog(@TypeOf(&(@as(anyerror!usize, 0) catch |err| return err)));
    @compileLog(@TypeOf(&(@as(anyerror!usize, 0) catch |err| switch (err) {
        else => return err,
    })));
}
Compile Log Output:
@as(type, *const usize)
@as(type, *const usize)
@as(type, *const usize)
@as(type, usize)

this didnt happen in 0.11, im guessing its caused by #18173
interestingly if you take the address of the switch itself it becomes correct

@compileLog(@TypeOf((@as(anyerror!usize, 0) catch |err| &switch (err) {
    else => return err,
})));

@as(type, *const usize)

Expected Behavior

all logs should be *const usize

Compile Log Output:
@as(type, *const usize)
@as(type, *const usize)
@as(type, *const usize)
@as(type, *const usize)

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