0
0
mirror of https://github.com/vim/vim.git synced 2025-11-15 23:14:06 -05:00

patch 8.2.3261: Vim9: when compiling repeat(123, N) return type is number

Problem:    Vim9: when compiling repeat(123, N) return type is number.
Solution:   Make return type a string. (closes #8664)
This commit is contained in:
Bram Moolenaar
2021-07-31 22:03:59 +02:00
parent 335c8c7b20
commit 1780f08ba4
3 changed files with 19 additions and 4 deletions

View File

@@ -930,6 +930,13 @@ ret_first_arg(int argcount, type_T **argtypes)
if (argcount > 0)
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 *
@@ -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,

View File

@@ -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()

View File

@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3261,
/**/
3260,
/**/