We implemented this check for TigreBeetle, there’s a relatively straightforward approximation: any non-pub symbol must be mentioned twice in its declaring file:
I think stuffing something like that into ASTGen in the Zig compiler itself might be a good idea!
But in general, yeah, the fundamental grain of the language is that only the used code is type-checked. My mental model for Zig is that itis just an interpreted language, which runs your pub fn main when you invoke zig build-exe, with the caveat that if something is not yet known (e.g., values of runtime-known CLI arguments), the interpreter evaluates Zig code not to a value like 92 but to a snippet of machine code like add eax, ebx. Fighting this generally won’t lead to happiness, you need to work with unique character of every language, rather than against it.
There are both the benefits and the drawbacks to the lazy approach, you want to embrace the benefits and minimize the drawbacks! See, e.g., how you can leverage comptime reflection for tests: Swarm Testing Data Structures.