From 2dde7ff5ba44c53250d93843f61c22a8835f8902 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 23 Aug 2022 09:52:59 +0300 Subject: [PATCH] strconv: deprecate v_sprintf in favor of string interpolation --- vlib/strconv/vprintf.c.v | 2 ++ vlib/v/checker/fn.v | 2 +- .../tests/passing_expr_to_fn_expecting_voidptr.out | 10 +++++----- .../tests/passing_expr_to_fn_expecting_voidptr.vv | 6 ++++-- vlib/v/live/executable/reloader.v | 3 +-- vlib/v/pref/pref.v | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/vlib/strconv/vprintf.c.v b/vlib/strconv/vprintf.c.v index ec8d5f078..dbea0e149 100644 --- a/vlib/strconv/vprintf.c.v +++ b/vlib/strconv/vprintf.c.v @@ -23,6 +23,7 @@ enum Char_parse_state { } // v_printf prints a sprintf-like formated `string` to the terminal. +[deprecated: 'use string interpolation instead'] pub fn v_printf(str string, pt ...voidptr) { print(v_sprintf(str, ...pt)) } @@ -34,6 +35,7 @@ pub fn v_printf(str string, pt ...voidptr) { // x := 3.141516 // assert strconv.v_sprintf('aaa %G', x) == 'aaa 3.141516' // ``` +[deprecated: 'use string interpolation instead'] [manualfree] pub fn v_sprintf(str string, pt ...voidptr) string { mut res := strings.new_builder(pt.len * 16) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 3c00ee7ab..432cf40c5 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -750,7 +750,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) } } if !func.is_pub && func.language == .v && func.name.len > 0 && func.mod.len > 0 - && func.mod != c.mod { + && func.mod != c.mod && !c.pref.is_test { c.error('function `$func.name` is private', node.pos) } if !isnil(c.table.cur_fn) && !c.table.cur_fn.is_deprecated && func.is_deprecated { diff --git a/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.out b/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.out index 1acbdb5e3..dada81488 100644 --- a/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.out +++ b/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.out @@ -1,5 +1,5 @@ -vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv:3:31: error: expression cannot be passed as `voidptr` - 1 | import strconv - 2 | - 3 | strconv.v_printf('%02.02f\n', 1.1) - | ~~~ +vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv:5:23: error: expression cannot be passed as `voidptr` + 3 | } + 4 | + 5 | myprintf('%02.02f\n', 1.1) + | ~~~ diff --git a/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv b/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv index 1b3bc3988..23e816444 100644 --- a/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv +++ b/vlib/v/checker/tests/passing_expr_to_fn_expecting_voidptr.vv @@ -1,3 +1,5 @@ -import strconv +fn myprintf(s string, x voidptr) { -strconv.v_printf('%02.02f\n', 1.1) +} + +myprintf('%02.02f\n', 1.1) diff --git a/vlib/v/live/executable/reloader.v b/vlib/v/live/executable/reloader.v index 828a5f1b8..f8643693a 100644 --- a/vlib/v/live/executable/reloader.v +++ b/vlib/v/live/executable/reloader.v @@ -3,7 +3,6 @@ module executable import os import time import dl -import strconv import v.live pub const ( @@ -84,7 +83,7 @@ fn compile_lib(mut r live.LiveReloadInfo) ?string { } fn current_shared_library_path(mut r live.LiveReloadInfo) (string, string) { - lib_path := strconv.v_sprintf(r.so_name_template.replace('\\', '\\\\'), r.reloads) + lib_path := r.so_name_template.replace('\\', '\\\\').replace('%d', r.reloads.str()) lib_path_with_extension := lib_path + r.so_extension return lib_path, lib_path_with_extension } diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 5e78944dd..b881ddf71 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -118,6 +118,7 @@ pub mut: is_debug bool // turned on by -g or -cg, it tells v to pass -g to the C backend compiler. is_vlines bool // turned on by -g (it slows down .tmp.c generation slightly). is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run + show_timings bool // show how much time each compiler stage took is_fmt bool is_vet bool is_vweb bool // skip _ var warning in templates @@ -201,7 +202,6 @@ pub mut: check_only bool // same as only_check_syntax, but also runs the checker experimental bool // enable experimental features skip_unused bool // skip generating C code for functions, that are not used - show_timings bool // show how much time each compiler stage took // use_color ColorOutput // whether the warnings/errors should use ANSI color escapes. cleanup_files []string // list of temporary *.tmp.c and *.tmp.c.rsp files. Cleaned up on successfull builds. -- 2.30.2