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(...@@ -302,13 +302,13 @@ pub fn format(
302 // Parse the width parameter302 // Parse the width parameter
303 options.width = init: {303 options.width = init: {
304 if (comptime parser.maybe('[')) {304 if (comptime parser.maybe('[')) {
305 const arg_name = parser.until(']');305 const arg_name = comptime parser.until(']');
306306
307 if (!comptime parser.maybe(']')) {307 if (!comptime parser.maybe(']')) {
308 @compileError("Expected closing ]");308 @compileError("Expected closing ]");
309 }309 }
310310
311 const index = meta.fieldIndex(ArgsType, arg_name) orelse311 const index = comptime meta.fieldIndex(ArgsType, arg_name) orelse
312 @compileError("No argument with name '" ++ arg_name ++ "'");312 @compileError("No argument with name '" ++ arg_name ++ "'");
313 const arg_index = comptime arg_state.nextArg(index);313 const arg_index = comptime arg_state.nextArg(index);
314314
...@@ -328,13 +328,13 @@ pub fn format(...@@ -328,13 +328,13 @@ pub fn format(
328 // Parse the precision parameter328 // Parse the precision parameter
329 options.precision = init: {329 options.precision = init: {
330 if (comptime parser.maybe('[')) {330 if (comptime parser.maybe('[')) {
331 const arg_name = parser.until(']');331 const arg_name = comptime parser.until(']');
332332
333 if (!comptime parser.maybe(']')) {333 if (!comptime parser.maybe(']')) {
334 @compileError("Expected closing ]");334 @compileError("Expected closing ]");
335 }335 }
336336
337 const arg_i = meta.fieldIndex(ArgsType, arg_name) orelse337 const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse
338 @compileError("No argument with name '" ++ arg_name ++ "'");338 @compileError("No argument with name '" ++ arg_name ++ "'");
339 const arg_to_use = comptime arg_state.nextArg(arg_i);339 const arg_to_use = comptime arg_state.nextArg(arg_i);
340340
...@@ -2452,30 +2452,18 @@ test "type" {...@@ -2452,30 +2452,18 @@ test "type" {
2452}2452}
24532453
2454test "named arguments" {2454test "named arguments" {
2455 if (true) {
2456 // TODO this regressed in the branch and I don't know why
2457 return error.SkipZigTest;
2458 }
2459 try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' });2455 try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' });
2460 try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });2456 try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" });
2461 try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });2457 try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" });
2462}2458}
24632459
2464test "runtime width specifier" {2460test "runtime width specifier" {
2465 if (true) {
2466 // TODO this regressed in the branch and I don't know why
2467 return error.SkipZigTest;
2468 }
2469 var width: usize = 9;2461 var width: usize = 9;
2470 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });2462 try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width });
2471 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });2463 try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width });
2472}2464}
24732465
2474test "runtime precision specifier" {2466test "runtime precision specifier" {
2475 if (true) {
2476 // TODO this regressed in the branch and I don't know why
2477 return error.SkipZigTest;
2478 }
2479 var number: f32 = 3.1415;2467 var number: f32 = 3.1415;
2480 var precision: usize = 2;2468 var precision: usize = 2;
2481 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });2469 try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });