zig icon indicating copy to clipboard operation
zig copied to clipboard

fix printing of unused args error in std.fmt

Open xdBronch opened this issue 2 years ago • 2 comments

currently the error from code like this

print("{}\n\"\x00", .{ 0, 0 });

yields this error

zig/lib/std/fmt.zig:202:18: error: unused argument in '{}
                                               "
            1 => @compileError("unused argument in '" ++ fmt ++ "'"),
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

this looks terrible and hurts readability, after this pr it gives

zig/lib/std/fmt.zig:202:18: error: unused argument in '{}\n\"\x00'
            1 => @compileError(comptimePrint("unused argument in '{}'", .{std.zig.fmtEscapes(fmt)})),
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

which matches the format string exactly

i feel like i remember there being an issue about this but i couldnt find anything, it couldve just been a random conversation i read. if it exists and someone can find it that would be wonderful :pray:

xdBronch avatar Dec 22 '23 21:12 xdBronch

LGTM. Great to see improvements to the fmt error cases. They can be annoying to map back the actual code.

I see test/cases/compile_errors/std.fmt_error_for_unused_arguments.zig has a related test case, may be worth following that example to add tests for the new behavior.

If you need ideas,

rootbeer avatar Dec 22 '23 21:12 rootbeer

thanks, yeah i saw that file earlier. its the only std test case in there which is a little weird imo but i guess fmt has lots of @compileErrors. im not sure it would be all that helpful to add a test case for this change since its just making edge cases behave more like how they shouldve from the start, not really new behavior, at least the way i see it

xdBronch avatar Dec 22 '23 21:12 xdBronch

i realized that there really wasnt much point not testing this so i adjusted a test to account for this change and added a similar change + test for the opposite case.

xdBronch avatar Jan 08 '24 18:01 xdBronch

Closing, wrong direction for the project to take. Let us direct our efforts towards the root problems.

andrewrk avatar Jan 09 '24 22:01 andrewrk

im disappointed but i understand, the fix/improvement being in the compiler itself will be much better

xdBronch avatar Jan 09 '24 23:01 xdBronch

Thanks for understanding. If I don't do this, people will pile even more hacks on top of your code. I've seen it happen

andrewrk avatar Jan 10 '24 01:01 andrewrk