ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.12k stars 2.49k forks source link

Highlight the actual file where the error is occurring for `@compileError()` #20531

Closed Lioncat2002 closed 2 months ago

Lioncat2002 commented 3 months ago

Zig Version

0.12.0

Steps to Reproduce and Observed Output

Here's a very simple example of the problem: main.zig

const std = @import("std");

pub fn main() !void {
    std.debug.print("{}", .{"codebase"});//this will cause compile error coz of incorrect formatting
}

Error: (after running with zig build run -freference-trace

run
└─ run zig_test
   └─ install
      └─ install zig_test
         └─ zig build-exe zig_test Debug native 1 errors
C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\fmt.zig:651:17: error: cannot format array without a specifier (i.e. {s} or {any})
                @compileError("cannot format array without a specifier (i.e. {s} or {any})");
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    formatType__anon_3983: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\fmt.zig:615:38
    format__anon_3746: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\fmt.zig:185:23
    print__anon_3516: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\io\Writer.zig:23:26
    print: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\io.zig:324:47
    dumpSegfaultInfoWindows: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\debug.zig:2705:20
    handleSegfaultWindowsExtra: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\debug.zig:2681:17
    handleSegfaultWindows: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\debug.zig:2653:45
    attachSegfaultHandler: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\debug.zig:2542:83
    maybeEnableSegfaultHandler: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\debug.zig:2523:18
    WinStartup: C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\lib\std\start.zig:348:14
error: the following command failed with 1 compilation errors:
C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\zig.exe build-exe -freference-trace=256 -ODebug -Mroot=D:\zig\zig_test\src\main.zig --cache-dir D:\zig\zig_test\zig-cache --global-cache-dir C:\Users\gamed\AppData\Local\zig --name zig_test --listen=-
Build Summary: 2/7 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run zig_test transitive failure
   ├─ zig build-exe zig_test Debug native 1 errors
   └─ install transitive failure
      └─ install zig_test transitive failure
         └─ zig build-exe zig_test Debug native (reused)
error: the following build command failed with exit code 1:
D:\zig\zig_test\zig-cache\o\d45c87b46c43d54d58069300ab66325c\build.exe C:\ProgramData\chocolatey\lib\zig\tools\zig-windows-x86_64-0.12.0\zig.exe D:\zig\zig_test D:\zig\zig_test\zig-cache C:\Users\gamed\AppData\Local\zig --seed 0x601b4a91 -Z40f512679b658625 run -freference-trace

The error doesn't tell that the actual error is happening because of incorrect formatting in main.zig. It instead highlights the file where the @compileError() is written

Expected Output

The @compileError() should ideally highlight where the actual error is happening. Something like: main.zig: error: cannot format array without a specifier (i.e. {s} or {any})

and then add the trace to fmt.zig

tact1m4n3 commented 3 months ago

I've noticed the same thing today. It took me a while to find what was wrong with my code :)). It would be nice for a trace to be displayed.

alichraghi commented 3 months ago

Duplicate of #19116