From 93dbf30dcf04ba7b0b303ef9a2e5343d0abf1d9c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 17 May 2021 19:53:46 -0700 Subject: [PATCH] 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. --- lib/std/fmt.zig | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 5a36e0dff4..ce7b7d8c4d 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -302,13 +302,13 @@ pub fn format( // Parse the width parameter options.width = init: { if (comptime parser.maybe('[')) { - const arg_name = parser.until(']'); + const arg_name = comptime parser.until(']'); if (!comptime parser.maybe(']')) { @compileError("Expected closing ]"); } - const index = meta.fieldIndex(ArgsType, arg_name) orelse + const index = comptime meta.fieldIndex(ArgsType, arg_name) orelse @compileError("No argument with name '" ++ arg_name ++ "'"); const arg_index = comptime arg_state.nextArg(index); @@ -328,13 +328,13 @@ pub fn format( // Parse the precision parameter options.precision = init: { if (comptime parser.maybe('[')) { - const arg_name = parser.until(']'); + const arg_name = comptime parser.until(']'); if (!comptime parser.maybe(']')) { @compileError("Expected closing ]"); } - const arg_i = meta.fieldIndex(ArgsType, arg_name) orelse + const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse @compileError("No argument with name '" ++ arg_name ++ "'"); const arg_to_use = comptime arg_state.nextArg(arg_i); @@ -2452,30 +2452,18 @@ test "type" { } test "named arguments" { - if (true) { - // TODO this regressed in the branch and I don't know why - return error.SkipZigTest; - } try expectFmt("hello world!", "{s} world{c}", .{ "hello", '!' }); try expectFmt("hello world!", "{[greeting]s} world{[punctuation]c}", .{ .punctuation = '!', .greeting = "hello" }); try expectFmt("hello world!", "{[1]s} world{[0]c}", .{ '!', "hello" }); } test "runtime width specifier" { - if (true) { - // TODO this regressed in the branch and I don't know why - return error.SkipZigTest; - } var width: usize = 9; try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width }); try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width }); } test "runtime precision specifier" { - if (true) { - // TODO this regressed in the branch and I don't know why - return error.SkipZigTest; - } var number: f32 = 3.1415; var precision: usize = 2; try expectFmt("3.14e+00", "{:1.[1]}", .{ number, precision });