Skip to content

Commit 55e9366

Browse files
committed
patch 9.0.0437: no error when custom completion function returns wrong type
Problem: No error when a custom completion function returns something else than the expected list. Solution: Give an error. (closes #11100)
1 parent 71b6d33 commit 55e9366

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,4 +3333,6 @@ EXTERN char e_string_number_list_or_blob_required_for_argument_nr[]
33333333
INIT(= N_("E1301: String, Number, List or Blob required for argument %d"));
33343334
EXTERN char e_script_variable_was_deleted[]
33353335
INIT(= N_("E1302: Script variable was deleted"));
3336+
EXTERN char e_custom_list_completion_function_does_not_return_list_but_str[]
3337+
INIT(= N_("E1303: Custom list completion function does not return a List but a %s"));
33363338
#endif

src/eval.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ call_func_retstr(
842842
* Call Vim script function "func" and return the result as a List.
843843
* Uses "argv" and "argc" as call_func_retstr().
844844
* Returns NULL when there is something wrong.
845+
* Gives an error when the returned value is not a list.
845846
*/
846847
void *
847848
call_func_retlist(
@@ -856,6 +857,8 @@ call_func_retlist(
856857

857858
if (rettv.v_type != VAR_LIST)
858859
{
860+
semsg(_(e_custom_list_completion_function_does_not_return_list_but_str),
861+
vartype_name(rettv.v_type));
859862
clear_tv(&rettv);
860863
return NULL;
861864
}

src/testdir/test_usercommands.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ func Test_usercmd_custom()
666666
return "a\nb\n"
667667
endfunc
668668
command -nargs=* -complete=customlist,T1 TCmd1
669-
call feedkeys(":TCmd1 \<C-A>\<C-B>\"\<CR>", 'xt')
669+
call assert_fails('call feedkeys(":TCmd1 \<C-A>\<C-B>\"\<CR>", "xt")', 'E1303: Custom list completion function does not return a List but a string')
670670
call assert_equal('"TCmd1 ', @:)
671671
delcommand TCmd1
672672
delfunc T1
@@ -675,7 +675,7 @@ func Test_usercmd_custom()
675675
return {}
676676
endfunc
677677
command -nargs=* -complete=customlist,T2 TCmd2
678-
call feedkeys(":TCmd2 \<C-A>\<C-B>\"\<CR>", 'xt')
678+
call assert_fails('call feedkeys(":TCmd2 \<C-A>\<C-B>\"\<CR>", "xt")', 'E1303: Custom list completion function does not return a List but a dict')
679679
call assert_equal('"TCmd2 ', @:)
680680
delcommand TCmd2
681681
delfunc T2

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ static char *(features[]) =
703703

704704
static int included_patches[] =
705705
{ /* Add new patch number below this line */
706+
/**/
707+
437,
706708
/**/
707709
436,
708710
/**/

0 commit comments

Comments
 (0)