| author | |
| committer | |
| log | 540b52931aeeee7c72c73361118d07ab986cf048 |
| tree | 6530a554de35d5b84fce69ddec0009d2de0301e2 |
| parent | b2879825d7e59fc40f3defe272039d723b692f43 |
Use fmt in fmt so the number in the error message is fmt'd3 files changed, 15 insertions(+), 2 deletions(-)
doc/langref.html.in+1-1| ... | ... | @@ -6262,7 +6262,7 @@ pub fn printValue(self: *Writer, value: anytype) !void { |
| 6262 | 6262 | <p> |
| 6263 | 6263 | And now, what happens if we give too many arguments to {#syntax#}printf{#endsyntax#}? |
| 6264 | 6264 | </p> |
| 6265 | {#code_begin|test_err|Unused arguments#} | |
| 6265 | {#code_begin|test_err|Unused argument in "here is a string: '{s}' here is a number: {}#} | |
| 6266 | 6266 | const print = @import("std").debug.print; |
| 6267 | 6267 | |
| 6268 | 6268 | const a_number: i32 = 1234; |
lib/std/fmt.zig+6-1| ... | ... | @@ -359,7 +359,12 @@ pub fn format( |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | if (comptime arg_state.hasUnusedArgs()) { |
| 362 | @compileError("Unused arguments"); | |
| 362 | const missing_count = arg_state.args_len - @popCount(ArgSetType, arg_state.used_args); | |
| 363 | switch (missing_count) { | |
| 364 | 0 => unreachable, | |
| 365 | 1 => @compileError("Unused argument in \"" ++ fmt ++ "\""), | |
| 366 | else => @compileError((comptime comptimePrint("{d}", .{missing_count})) ++ " unused arguments in \"" ++ fmt ++ "\""), | |
| 367 | } | |
| 363 | 368 | } |
| 364 | 369 | } |
| 365 | 370 |
test/compile_errors.zig+8| ... | ... | @@ -2,6 +2,14 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("std.fmt error for unused arguments", | |
| 6 | \\pub fn main() !void { | |
| 7 | \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); | |
| 8 | \\} | |
| 9 | , &.{ | |
| 10 | \\error: 10 unused arguments in "{d} {d} {d} {d} {d}" | |
| 11 | }); | |
| 12 | ||
| 5 | 13 | cases.add("lazy pointer with undefined element type", |
| 6 | 14 | \\export fn foo() void { |
| 7 | 15 | \\ comptime var T: type = undefined; |