Skip to content

regression: ast gen fails to catch incorrect by ref error captures #18583

@travisstaloch

Description

@travisstaloch

Zig Version

0.12.0-dev.2158+4f2009de1

Steps to Reproduce and Observed Behavior

this is a follow up to #18579 and addresses some changes made in #18173.

these code snippets below were produced by @Techatrix and i think he may address them soon. we noticed this while working on #18579 but decided that it deserves its own issue.

with 0.11.0 the following produced a compile error error set cannot be captured by reference. but now the compiler allows it. i think this is a regression.

comptime {
    const e: error{A}!u32 = error.A;

    e catch |err| switch (err) {
        error.A => |*foo| {
            @compileLog(foo);
        },
    };
}
// 

The compiler also doesn't seem to catch the following syntax error:

comptime {
    const e: error{A}!u32 = error.A;

    if (e) |_| {} else |err| switch (err + "I can put anything I want here") {
        error.A => {},
    }
}

This is a little beyond me so I'm hoping that @Techatrix or another contributor knows what needs to be done here.

Expected Behavior

should be a compile error like it was in 0.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions