]> granicus.if.org Git - vim/commitdiff
patch 8.1.1835: cannot use printf() as a method v8.1.1835
authorBram Moolenaar <Bram@vim.org>
Fri, 9 Aug 2019 22:13:30 +0000 (00:13 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 9 Aug 2019 22:13:30 +0000 (00:13 +0200)
Problem:    Cannot use printf() as a method.
Solution:   Pass the base as the second argument to printf().

runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_method.vim
src/version.c

index 981121f8a19367b56e7523722553f6f7f4034a17..62bcfc287b379e398896914915f34731eb409be0 100644 (file)
@@ -6739,7 +6739,11 @@ printf({fmt}, {expr1} ...)                               *printf()*
 <              May result in:
                        "  99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
 
-               Often used items are:
+               When used as a |method| the base is passed as the second
+               argument: >
+                       Compute()->printf("result: %d")
+
+<              Often used items are:
                  %s    string
                  %6S   string right-aligned in 6 display cells
                  %6s   string right-aligned in 6 bytes
index 29857d318a014467587132b50e36b4ec1959433d..7800aa9a7b32a30f8fe0dfde209114ad0b8c9c38 100644 (file)
@@ -733,7 +733,7 @@ static funcentry_T global_functions[] =
     {"pow",            2, 2, 0,          f_pow},
 #endif
     {"prevnonblank",   1, 1, 0,          f_prevnonblank},
-    {"printf",         1, 19, 0,         f_printf},
+    {"printf",         1, 19, FEARG_2,   f_printf},
 #ifdef FEAT_JOB_CHANNEL
     {"prompt_setcallback", 2, 2, 0,      f_prompt_setcallback},
     {"prompt_setinterrupt", 2, 2, 0,     f_prompt_setinterrupt},
index 310b5f22c724eb40a7a518911ea4b5266c3b7998..98c07fe3416c8bf474d8203be70bfd6b52cab9e1 100644 (file)
@@ -67,13 +67,15 @@ func Test_dict_method()
 endfunc
 
 func Test_string_method()
-  call assert_equal(['1', '2', '3'], '1 2 3'->split())
-  call assert_equal([1, 2, 3], '1 2 3'->split()->map({i, v -> str2nr(v)}))
-  call assert_equal([65, 66, 67], 'ABC'->str2list())
-  call assert_equal(3, 'ABC'->strlen())
-  call assert_equal('a^Mb^[c', "a\rb\ec"->strtrans())
-  call assert_equal(4, "aあb"->strwidth())
-  call assert_equal('axc', 'abc'->substitute('b', 'x', ''))
+  eval '1 2 3'->split()->assert_equal(['1', '2', '3'])
+  eval '1 2 3'->split()->map({i, v -> str2nr(v)})->assert_equal([1, 2, 3])
+  eval 'ABC'->str2list()->assert_equal([65, 66, 67])
+  eval 'ABC'->strlen()->assert_equal(3)
+  eval "a\rb\ec"->strtrans()->assert_equal('a^Mb^[c')
+  eval "aあb"->strwidth()->assert_equal(4)
+  eval 'abc'->substitute('b', 'x', '')->assert_equal('axc')
+
+  eval 'abc'->printf('the %s arg')->assert_equal('the abc arg')
 endfunc
 
 func Test_method_append()
index 2d06c7773e42909a7d96977743a9b1beeac60886..f10ea0896fa081ea9be6b796f112b2be9df9bd88 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1835,
 /**/
     1834,
 /**/