Forcing semantic analysis of a single .zig file

suppose i have the following source file, which exposes foo():

pub fn foo() u32 {
    return true;
}

obviously, my definition has a semantic error – which, as i understand it, isn’t necessarily flagged by the compiler useless some part of my program actually calls foo()

were i to invoke zig build-obj on this source (suppressing an output generation to speed-up the analysis), is there something i can do to force the compiler to perform some checking on foo() ???

would i add some “mock test” that calls foo() and then invoke zig test with options to suppress any output generation???

again, all i’m trying to do is catch the obvious semantic error in this file…

Do you mean something like this?

Or without build.zig?

actually, without… i have my own vscode extension, and will do something similar to what’s suggested in your reference…

what i did discover is std.test.refAllDecls* (described in this post), which basically does the trick…

i can now write something like:

test "this-file" {
    std.test.refAllDecls(@This());
}

and then invoke zig test -fno-emit-bin ... on this source file…

1 Like