Skip to content

using std.debug.print() on struct function twice causes unreachable code in analyze.cpp #11850

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

Closed
sylveon9 opened this issue Jun 12, 2022 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@sylveon9
Copy link

Zig Version

0.10.0-dev.2600+9360cfebc

Steps to Reproduce

I'm using the latest git commit as of right now, as I filled out in the version field, but it can also be reproduced on the Zig playground: https://zig-play.dev/

Minimal reproducible example:

const std = @import("std");

const St = struct {
    fn f() void {}
};

pub fn main() void {
    const st: St = undefined;
    std.debug.print("{}{}", .{st.f, st.f});
}
zig/src/stage1/analyze.cpp:7310 in const_values_equal. This is a bug in the Zig compiler.thread 31199 panic: 
Unable to dump stack trace: debug info stripped

This also causes the problem:

std.debug.print("{}", .{st.f});
std.debug.print("{}", .{st.f});

Printing once does not, and just outputs a normal compiler error as expected:

std.debug.print("{}", .{st.f});
/usr/lib/zig/std/fmt.zig:679:17: error: Unable to format type '(bound fn() void)'
        else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"),
                ^

Expected Behavior

The expected behavior is to output a normal and descriptive compiler error which shows the problem line.

Actual Behavior

The compiler reaches code marked unreachable in const_values_equal and crashes.

@sylveon9 sylveon9 added the bug Observed behavior contradicts documented or intended behavior label Jun 12, 2022
@Vexu Vexu added the stage1 The process of building from source via WebAssembly and the C backend. label Jun 12, 2022
@Vexu Vexu added this to the 0.12.0 milestone Jun 12, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 15, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 16, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 16, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 17, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 17, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 18, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 18, 2022
wooster0 added a commit to wooster0/zig that referenced this issue Dec 21, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 27, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

3 participants