Compiler doesn't show filename and line number of error

Hello, I’m new to Zig.
How can I get the filename and line number where the Compiler finds the error?
Guess we have the following code:

const std = @import("std");
const print = std.debug.print;

pub fn main() !void {
    const x = 123;
    print("x = {}\n", x);
}

The compiler just gives:

/home/user/.local/bin/zig/lib/std/fmt.zig:87:9: error: expected tuple or struct argument, found comptime_int
        @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Every other language compiler would have the output like:
/home/user/zsource/main.zig: line 6 col 23 : error: expected tuple…

I used “zig build-exe” and build system with “zig build”.
Getting the filename and line number would be very helpful,
otherwise I would be lost. Is there a setting for this?
I’m wondering how you guys find the errors in your source code.
Thank you, Joerg

-freference-trace is likely what you’re looking for

Without -freference-trace:

$ zig build-exe ziggit-2608.zig 
/home/ryan/Programming/zig/zig/lib/std/fmt.zig:87:9: error: expected tuple or struct argument, found comptime_int
        @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    print__anon_3755: /home/ryan/Programming/zig/zig/lib/std/io/writer.zig:28:34
    print__anon_2998: /home/ryan/Programming/zig/zig/lib/std/debug.zig:88:27
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

And with -freference-trace:

$ zig build-exe ziggit-2608.zig -freference-trace
/home/ryan/Programming/zig/zig/lib/std/fmt.zig:87:9: error: expected tuple or struct argument, found comptime_int
        @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    print__anon_3755: /home/ryan/Programming/zig/zig/lib/std/io/writer.zig:28:34
    print__anon_2998: /home/ryan/Programming/zig/zig/lib/std/debug.zig:88:27
    main: ziggit-2608.zig:6:10
    callMain: /home/ryan/Programming/zig/zig/lib/std/start.zig:585:32
    initEventLoopAndCallMain: /home/ryan/Programming/zig/zig/lib/std/start.zig:519:34
    callMainWithArgs: /home/ryan/Programming/zig/zig/lib/std/start.zig:469:12
    posixCallMainAndExit: /home/ryan/Programming/zig/zig/lib/std/start.zig:425:39
    _start: /home/ryan/Programming/zig/zig/lib/std/start.zig:338:40

The relevant part is main: ziggit-2608.zig:6:10

6 Likes

Cool, thank you.
I had to upgrade because it’s since version 0.12.0-dev available.