Mercurial > vim
changeset 25449:5dce28f92d04 v8.2.3261
patch 8.2.3261: Vim9: when compiling repeat(123, N) return type is number
Commit: https://github.com/vim/vim/commit/1780f08ba42837b6d4a5f0451117a79b2d49974a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 31 22:03:59 2021 +0200
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 https://github.com/vim/vim/issues/8664)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 31 Jul 2021 22:15:02 +0200 |
parents | cde84529a0a6 |
children | 88cb2ee8a901 |
files | src/evalfunc.c src/testdir/test_vim9_builtin.vim src/version.c |
diffstat | 3 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -931,6 +931,13 @@ ret_first_arg(int argcount, type_T **arg 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,
--- 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()