Pedantic / warning

I might be missing something, but I would like to have had a --pedantic or --warning option on Zig 0.15 (zig build and zig build-exe) to find things that have been deprecated in 0.15 or earler version but still work (in 0.15). I am referring to language constructs that might no longer work in some future version, some expected library changes (managed versions). Here is why:

I have code that I started a few years ago, and that I have upgraded for various compiler/library changes over the years. I have test for this code, but as soon as I start making changes for a new version (such as now for 0.16), I cannot run those tests until everything has been upgraded/fixed for the new version and it compiles again. In this particular case, after making several changes for 0.16 based on what the compiler complained about, I found that in some places I still use .{} (from a pre-0.14 period), instead of .empty ( which I use for any new code I write).

I would much prefer to have changed all of the .{} before doing any of the 0.16 changes, so that I could still run my tests (with 0.15) after that bunch of changes. Now, in order to allow for immediate testing, I have to roll-back my 0.16 specific changes, update .{} to .empty everywhere applicable, run tests. And after that re-apply the 0.16 specific changes necessary, that I previously found, after that fixing the next thing 0.16 complains about. And I have to hope that I don’t find anything else I could have done in 0.15, that I makes me want to roll-back to 0.15 only code, so I can test everything before proceeding.

I could of course re-read the release notes of the last few releases ( re-read because I tend to not understand and/or appreciate the significance of some of the changes on first reading), And then read through all of my 0.15 code, and update it before switching to 0.16. But it is easy to miss things and it woud be nice if the compiler helped with finding at least some of these depreciations, I would also be less likely to postpone “fixing” these until things no longer compile, if I had some automated way of finding the majore culprits.

I have no idea how difficult this is to implement. Or if this rather should be different (sub)command for zig or an option to the commands build and build-exe. It could also be some separate tool. For me this also doesn’t have to be in the first release of a new minor version (0.X.0), but it would be nice to have it later on, to clean up code before upgrading.

Is there some tool or zig option that I missed, that can analyse my 0.15 Zig code?

My idea is relatively simple: it is reasonable to forbid warnings during a release build, but not in the debug build. Some minor issues during debugging are not enough to interrupt testing of the entire process.

zig doesn’t have warnings, and they are not planned. The reasoning being warnings can be ignored.

There is a plan to still out put an exe/lib/obj when an error occurs, letting you run code up to the point of the error where it will panic.

This fulfils the use case of warnings, running code while ignoring pedantics and even hard errors (can your warnings do that :p) for the purposes of development, but still ensures they cannot be ignored easily as a pedantic panic will still remain.

(accepted proposal; not implemented yet)

5 Likes

I don’t see how that would help with finding deprecations in any way, for those running is not really necessary. Maybe the option (if added) should be --show-used-deprecations.

BTW, in my experience Zig already generates an executable on error: it is just an empty file with exec persmissions:

zig/zigclc » ls -lrt | tail -2
-rw-r--r--  1 anthon users 3169832 Apr 19 11:23 zigclc.zig
-rwxr-xr-x  1 anthon users       0 Apr 19 11:23 zigclc*

This is on macOS, and you can actually run the file, but nothing happens.

Ah sorry, I can’t read apparently :sweat_smile:

the proposal linked above seems to be what you want, it is accepted, and was implemented temporarily but reverted due to bugs.

what I said is planned, it is not implemented

I followed that when it was introduced. But I always thought that to be for function (and struct/unions) changes.. I.e. you should no longer call XYZManaged although it still functions in the current version.

It seems to me that the deprecations of .{} in favour of .empty, cannot be marked up with @deprecation in a library. But maybe the latter can be put into some compiler source position dealing with the .{} instead.

For context on the exe/lib/obj output on error: I don’t think there exists an issue about this, but see e.g. this comment:

I see. Maybe doing something like size: usize = @deprecated(0), and pub const empty: TheType = .{ .size = 0 } could work.

I couldnt find an issue either, but andrew has talked about it in at least one livestream