Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace trap (core dumped) on continue inside error switch #22287

Open
cyuria opened this issue Dec 22, 2024 · 1 comment · May be fixed by #22328
Open

trace trap (core dumped) on continue inside error switch #22287

cyuria opened this issue Dec 22, 2024 · 1 comment · May be fixed by #22328
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@cyuria
Copy link

cyuria commented Dec 22, 2024

Zig Version

0.14.0-dev.1911+3bf89f55c

Steps to Reproduce and Observed Behavior

The following snippet fails to compile with [1] 372270 trace trap (core dumped) zig build-exe minrepro.zig

fn dosomething() error{
    FirstError,
    SecondError,
}!void {
    return;
}

pub fn main() !void {
    dosomething() catch |err| errswitch: switch (err) {
        error.FirstError => continue :errswitch error.SecondError,
        error.SecondError => {},
    };
}

This snippet, which contains effectively the same behaviour, compiles as expected.

const MyErrors = enum {
    first,
    second,
};

fn dosomething() MyErrors {
    return .first;
}

pub fn main() !void {
    const result = dosomething();
    errhandling: switch (result) {
        .first => continue :errhandling .second,
        .second => {},
    }
}

Expected Behavior

The original snippet to compile, or at the very least contain a meaningful error message.

@cyuria cyuria added the bug Observed behavior contradicts documented or intended behavior label Dec 22, 2024
@cyuria
Copy link
Author

cyuria commented Dec 22, 2024

A workaround is to place the body code for the second prong into the body of the first prong, however this results in unnecessary code duplication. For example, take the following modified original snippet:

const std = @import("std");

fn dosomething() error{
    FirstError,
    SecondError,
}!void {
    return;
}

pub fn main() !void {
    var a: u32 = 0;
    dosomething() catch |err| switch (err) {
        error.FirstError => {
            std.log.err("something somewhere went terribly wrong", .{});
            //continue :errswitch error.SecondError;

            std.log.info("some important information regarding errors", .{});
        },
        error.SecondError => {
            std.log.info("some important information regarding errors", .{});
        },
    };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant