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

Show line of references when compilation fails #20315

Open
doongjohn opened this issue Jun 16, 2024 · 3 comments
Open

Show line of references when compilation fails #20315

doongjohn opened this issue Jun 16, 2024 · 3 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@doongjohn
Copy link

doongjohn commented Jun 16, 2024

Zig Version

0.14.0-dev.32+4aa15440c

Steps to Reproduce and Observed Output

fn someFunc(a: anytype) void {
    if (@TypeOf(a) != i32) {
        @compileError("you can't do this!");
    }
}

fn someFunc2(a: anytype) void {
    someFunc(a);
}

pub fn main() void {
    someFunc2(1.1);
}

This code fails to compile with this message:

❯ zig build
install
└─ install exp-zig
   └─ zig build-exe exp-zig Debug native 1 errors
src/main.zig:3:9: error: you can't do this!
        @compileError("you can't do this!");
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    someFunc2__anon_3324: src/main.zig:8:13
    main: src/main.zig:12:14
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

All necessary information is there. However the important part is where it is being called from: someFunc(1.1);
I think showing the line of references should help developers.

Expected Output

❯ zig build
install
└─ install exp-zig
   └─ zig build-exe exp-zig Debug native 1 errors
src/main.zig:3:9: error: you can't do this!
        @compileError("you can't do this!");
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    someFunc2__anon_3324: src/main.zig:8:13
    someFunc(a);
    ^~~~~~~~~~~
    main: src/main.zig:12:14
    someFunc2(1.1);
    ^~~~~~~~~~~~~~
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
@doongjohn doongjohn added the error message This issue points out an error message that is unhelpful and should be improved. label Jun 16, 2024
@doongjohn
Copy link
Author

I think this issue can be closed if it's considered duplicate of: #20294 (comment)

@doongjohn doongjohn changed the title Better error message for @compileError Show line of references when compilation fails Jun 16, 2024
@Vexu Vexu added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jun 16, 2024
@Vexu Vexu added this to the 0.15.0 milestone Jun 16, 2024
@Vexu
Copy link
Member

Vexu commented Jun 16, 2024

The lines are intentionally not included to reduce noise in the output but could be added if -freference-trace is specified.

@Not-Nik
Copy link

Not-Nik commented Jun 17, 2024

Maybe this can be specifically enabled in the @compileError, maybe with a .TraceCall or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants