summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-07-31 22:03:59 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-31 22:03:59 +0200
commit1780f08ba42837b6d4a5f0451117a79b2d49974a (patch)
tree344aba2fa3ce158403fac40e1a02a381b09b9d8b
parent335c8c7b206df776b59fb63a1c7f91c8b1425398 (diff)
downloadvim-git-1780f08ba42837b6d4a5f0451117a79b2d49974a.tar.gz
patch 8.2.3261: Vim9: when compiling repeat(123, N) return type is numberv8.2.3261
Problem: Vim9: when compiling repeat(123, N) return type is number. Solution: Make return type a string. (closes #8664)
-rw-r--r--src/evalfunc.c9
-rw-r--r--src/testdir/test_vim9_builtin.vim12
-rw-r--r--src/version.c2
3 files changed, 19 insertions, 4 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 87b498a49..23a39aa4f 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -931,6 +931,13 @@ ret_first_arg(int argcount, type_T **argtypes)
return argtypes[0];
return &t_void;
}
+ static type_T *
+ret_repeat(int argcount UNUSED, type_T **argtypes)
+{
+ if (argtypes[0] == &t_number)
+ return &t_string;
+ return argtypes[0];
+}
// for map(): returns first argument but item type may differ
static type_T *
ret_first_cont(int argcount UNUSED, type_T **argtypes)
@@ -1813,7 +1820,7 @@ static funcentry_T global_functions[] =
{"rename", 2, 2, FEARG_1, arg2_string,
ret_number_bool, f_rename},
{"repeat", 2, 2, FEARG_1, arg2_repeat,
- ret_first_arg, f_repeat},
+ ret_repeat, f_repeat},
{"resolve", 1, 1, FEARG_1, arg1_string,
ret_string, f_resolve},
{"reverse", 1, 1, FEARG_1, arg1_list_or_blob,
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index f700cad24..f4d7448f5 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -2558,9 +2558,15 @@ enddef
def Test_repeat()
CheckDefAndScriptFailure2(['repeat(1.1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E1224: String, Number or List required for argument 1')
CheckDefAndScriptFailure2(['repeat({a: 10}, 2)'], 'E1013: Argument 1: type mismatch, expected string but got dict<', 'E1224: String, Number or List required for argument 1')
- assert_equal('aaa', repeat('a', 3))
- assert_equal('111', repeat(1, 3))
- assert_equal([1, 1, 1], repeat([1], 3))
+ var lines =<< trim END
+ assert_equal('aaa', repeat('a', 3))
+ assert_equal('111', repeat(1, 3))
+ assert_equal([1, 1, 1], repeat([1], 3))
+ var s = '-'
+ s ..= repeat(5, 3)
+ assert_equal('-555', s)
+ END
+ CheckDefAndScriptSuccess(lines)
enddef
def Test_resolve()
diff --git a/src/version.c b/src/version.c
index cbb028307..e3a6cb518 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3261,
+/**/
3260,
/**/
3259,