authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 19:53:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 19:53:46-07:00
log93dbf30dcf04ba7b0b303ef9a2e5343d0abf1d9c
treeb002f086d6ecaa2c53e58cec26066c490f31d92b
parent615d45da779842715a3ab65b59233e9cfb4fa122

std.fmt: fix regressions from master

A previous commit from this branch incorrectly changed the usage of `comptime` keyword, and broke the std lib tests. This commit adds `comptime` to a few function calls, correcting the behavior.

1 files changed, 4 insertions(+), 16 deletions(-)

lib/std/fmt.zig+4-16
......@@ -302,13 +302,13 @@ pub fn format(
302302 // Parse the width parameter
303303 options.width = init: {
304304 if (comptime parser.maybe('[')) {
305 const arg_name = parser.until(']');
305 const arg_name = comptime parser.until(']');
306306
307307 if (!comptime parser.maybe(']')) {
308308 @compileError("Expected closing ]");
309309 }
310310
311 const index = meta.fieldIndex(ArgsType, arg_name) orelse
311 const index = comptime meta.fieldIndex(ArgsType, arg_name) orelse
312312 @compileError("No argument with name '" ++ arg_name ++ "'");
313313 const arg_index = comptime arg_state.nextArg(index);
314314
......@@ -328,13 +328,13 @@ pub fn format(
328328 // Parse the precision parameter
329329 options.precision = init: {
330330 if (comptime parser.maybe('[')) {
331 const arg_name = parser.until(']');
331 const arg_name = comptime parser.until(']');
332332
333333 if (!comptime parser.maybe(']')) {
334334 @compileError("Expected closing ]");
335335 }
336336
337 const arg_i = meta.fieldIndex(ArgsType, arg_name) orelse
337 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse
338338 @compileError("No argument with name '" ++ arg_name ++ "'");
339339 const arg_to_use = comptime arg_state.nextArg(arg_i);
340340
......@@ -2452,30 +2452,18 @@ test "type" {
24522452}
24532453
24542454test "named arguments" {
2455 if (true) {
2456 // TODO this regressed in the branch and I don't know why
2457 return error.SkipZigTest;
2458 }
24592455 try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' });
24602456 try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });
24612457 try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });
24622458}
24632459
24642460test "runtime width specifier" {
2465 if (true) {
2466 // TODO this regressed in the branch and I don't know why
2467 return error.SkipZigTest;
2468 }
24692461 var width: usize = 9;
24702462 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
24712463 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
24722464}
24732465
24742466test "runtime precision specifier" {
2475 if (true) {
2476 // TODO this regressed in the branch and I don't know why
2477 return error.SkipZigTest;
2478 }
24792467 var number: f32 = 3.1415;
24802468 var precision: usize = 2;
24812469 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });