fix printing of unused args error in std.fmt
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:
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,
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
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.
Closing, wrong direction for the project to take. Let us direct our efforts towards the root problems.
im disappointed but i understand, the fix/improvement being in the compiler itself will be much better
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