Skip to content

catch continue doesn't handle error return trace frame popping correctly #13618

@squeek502

Description

@squeek502

Zig Version

0.11.0-dev.3+0bbb00035

Steps to Reproduce and Observed Behavior

fn foo() !void {
    return error.UhOh;
}

pub fn main() !void {
    var i: usize = 0;
    while (i < 3) : (i += 1) {
        foo() catch continue;
    }
    return error.UnrelatedError;
}

results in error.UhOh erroneously showing up in the trace multiple times:

> zig run 1923.zig
error: UnrelatedError
C:/Users/Ryan/Programming/Zig/tmp/1923.zig:2:5: 0x7ff71319128e in foo (1923.exe.obj)
    return error.UhOh;
    ^
C:/Users/Ryan/Programming/Zig/tmp/1923.zig:2:5: 0x7ff71319128e in foo (1923.exe.obj)
    return error.UhOh;
    ^
C:/Users/Ryan/Programming/Zig/tmp/1923.zig:2:5: 0x7ff71319128e in foo (1923.exe.obj)
    return error.UhOh;
    ^
C:/Users/Ryan/Programming/Zig/tmp/1923.zig:10:5: 0x7ff7131913ef in main (1923.exe.obj)
    return error.UnrelatedError;
    ^

(related to #12837 and #1923 (cc @topolarity))

Also worth noting that if the catch continue is changed to catch break then error.UhOh (correctly) doesn't show up in the trace.

Expected Behavior

> zig run 1923.zig
error: UnrelatedError
C:/Users/Ryan/Programming/Zig/tmp/1923.zig:10:5: 0x7ff7131913ef in main (1923.exe.obj)
    return error.UnrelatedError;
    ^

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