ziglang / zig

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

@compileError reference trace lost when return type is resolve through anytype arg introspection #19116

Open nektro opened 6 months ago

nektro commented 6 months ago

Zig Version

0.12.0-dev.1828+225fe6ddb

Steps to Reproduce and Observed Behavior

test {
    _ = foo();
}

fn foo() void {
    _ = foo2();
}

fn foo2() void {
    _ = bar(1);
}

fn bar(x: anytype) switch (@TypeOf(x)) {
    u8 => void,
    comptime_int => @compileError("whoops!"),
    else => u32,
} {
    //
}
test.zig:15:21: error: whoops!
    comptime_int => @compileError("whoops!"),
                    ^~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    foo: test.zig:6:9
    test_0: test.zig:2:9

Expected Behavior

reference trace is missing foo2: test.zig:10:9 line

rohlem commented 6 months ago

Similar scenario observed in https://github.com/ziglang/zig/issues/17103#issuecomment-1712795905 , though this issue's title is a better and more accurate description.

perillo commented 6 months ago

A shorter reproducer:

const std = @import("std");

pub fn main() void {
    std.debug.print("{}\n", .{""});
}

This seems a regression, because I remember that in the recent past it worked correctly.