Skip to content

Panic in compiler when user code has function named panic #22465

@widlarizer

Description

@widlarizer

Zig Version

0.14.0-dev.2634+b36ea592b

Steps to Reproduce and Observed Behavior

const std = @import("std");

fn maybeError(x: u32) !u32 {
    return if (x % 2 == 0) error.Error else x;
}

export fn main() noreturn {
    const x = maybeError(5) catch panic();
    std.debug.print("{}\n", .{x});

    while (true) {}
}

pub fn panic() noreturn {
    while (true) {}
}

zig build-obj main.zig has the following output

thread 19206 panic: parameter count mismatch calling builtin fn, expected 0, found 3
Unable to dump stack trace: debug info stripped
fish: Job 1, 'nix run 'github:mitchellh/zig-o…' terminated by signal SIGABRT (Abort)

Expected Behavior

0.13.0 prints an error and doesn't crash:

/nix/store/s3nq31mhm8gxkq691p5w6q61ficw1hvr-zig-0.13.0/lib/std/builtin.zig:751:9: error: expected type 'fn ([]const u8, ?*builtin.StackTrace, ?usize) noreturn', found 'fn () noreturn'
    root.panic
    ~~~~^~~~~~
/nix/store/s3nq31mhm8gxkq691p5w6q61ficw1hvr-zig-0.13.0/lib/std/builtin.zig:751:9: note: function with 0 parameters cannot cast into a function with 3 parameters

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions