patch 9.1.1219: Strange error with wrong type for matchfuzzy() "camelcase"
Commit: https://github.com/vim/vim/commit/c4815c157b27923001e44bfd241fb540bf1fb518 Author: zeertzjq <zeert...@outlook.com> Date: Tue Mar 18 20:28:00 2025 +0100 patch 9.1.1219: Strange error with wrong type for matchfuzzy() "camelcase" Problem: Strange error with type for matchfuzzy() "camelcase". Solution: Show the error "Invalid value for argument camelcase" instead of "Invalid argument: camelcase" (zeertzjq). Note that using tv_get_string() will lead to confusion, as when the value cannot be converted to a string tv_get_string() will also give an error about that, but "camelcase" takes a boolean, not a string. Also don't use tv_get_string() for the "limit" argument above. closes: #16926 Signed-off-by: zeertzjq <zeert...@outlook.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 3456093d2..bb6f9172e 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -1,4 +1,4 @@ -*builtin.txt* For Vim version 9.1. Last change: 2025 Mar 16 +*builtin.txt* For Vim version 9.1. Last change: 2025 Mar 18 VIM REFERENCE MANUAL by Bram Moolenaar @@ -7277,7 +7277,7 @@ matchfuzzy({list}, {str} [, {dict}]) *matchfuzzy()* returned. Zero means no limit. camelcase Use enhanced camel case scoring making results better suited for completion related to - programming languages. Default is v:true + programming languages. Defaults to v:true. If {list} is a list of dictionaries, then the optional {dict} argument supports the following additional items: diff --git a/src/search.c b/src/search.c index c7ae4f8e2..2698358c0 100644 --- a/src/search.c +++ b/src/search.c @@ -5000,7 +5000,8 @@ do_fuzzymatch(typval_T *argvars, typval_T *rettv, int retmatchpos) || di->di_tv.vval.v_string == NULL || *di->di_tv.vval.v_string == NUL) { - semsg(_(e_invalid_argument_str), tv_get_string(&di->di_tv)); + semsg(_(e_invalid_value_for_argument_str_str), "key", + tv_get_string(&di->di_tv)); return; } key = tv_get_string(&di->di_tv); @@ -5019,21 +5020,21 @@ do_fuzzymatch(typval_T *argvars, typval_T *rettv, int retmatchpos) { if (di->di_tv.v_type != VAR_NUMBER) { - semsg(_(e_invalid_argument_str), tv_get_string(&di->di_tv)); + semsg(_(e_invalid_value_for_argument_str), "limit"); return; } max_matches = (long)tv_get_number_chk(&di->di_tv, NULL); } if ((di = dict_find(d, (char_u *)"camelcase", -1)) != NULL) - { + { if (di->di_tv.v_type != VAR_BOOL) { - semsg(_(e_invalid_argument_str), "camelcase"); + semsg(_(e_invalid_value_for_argument_str), "camelcase"); return; } camelcase = tv_get_bool_chk(&di->di_tv, NULL); - } + } if (dict_has_key(d, "matchseq")) matchseq = TRUE; diff --git a/src/testdir/test_matchfuzzy.vim b/src/testdir/test_matchfuzzy.vim index eb06cfe5c..7e35d3547 100644 --- a/src/testdir/test_matchfuzzy.vim +++ b/src/testdir/test_matchfuzzy.vim @@ -76,6 +76,7 @@ func Test_matchfuzzy() call assert_fails("let x = matchfuzzy(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') call assert_equal([], matchfuzzy(l, 'cam')) call assert_fails("let x = matchfuzzy(l, 'cam', {'text_cb' : []})", 'E921:') + call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 123})", 'E475: Invalid value for argument key: 123') call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : []})", 'E730:') call assert_fails("let x = matchfuzzy(l, 'cam', test_null_dict())", 'E1297:') call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : test_null_string()})", 'E475:') @@ -88,10 +89,15 @@ func Test_matchfuzzy() call assert_fails("let x = matchfuzzy(l, 'foo', {'key' : 'name'})", 'E730:') " camelcase - call assert_equal(['Cursor', 'CurSearch', 'CursorLine', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor'], - \ matchfuzzy(['Cursor', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'CurSearch', 'CursorLine'], 'Cur', {"camelcase": v:false})) call assert_equal(['lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'Cursor', 'CurSearch', 'CursorLine'], \ matchfuzzy(['Cursor', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'CurSearch', 'CursorLine'], 'Cur')) + call assert_equal(['lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'Cursor', 'CurSearch', 'CursorLine'], + \ matchfuzzy(['Cursor', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'CurSearch', 'CursorLine'], 'Cur', {"camelcase": v:true})) + call assert_equal(['Cursor', 'CurSearch', 'CursorLine', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor'], + \ matchfuzzy(['Cursor', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'CurSearch', 'CursorLine'], 'Cur', {"camelcase": v:false})) + call assert_equal(['things', 'sThings', 'thisThings'], + \ matchfuzzy(['things','sThings', 'thisThings'], 'thin', {'camelcase': v:false})) + call assert_fails("let x = matchfuzzy([], 'foo', {'camelcase': []})", 'E475: Invalid value for argument camelcase') " Test in latin1 encoding let save_enc = &encoding @@ -155,6 +161,7 @@ func Test_matchfuzzypos() call assert_fails("let x = matchfuzzypos(l, 'day', {'text_cb' : {a, b -> 1}})", 'E119:') call assert_equal([[], [], []], matchfuzzypos(l, 'cam')) call assert_fails("let x = matchfuzzypos(l, 'cam', {'text_cb' : []})", 'E921:') + call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : 123})", 'E475: Invalid value for argument key: 123') call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : []})", 'E730:') call assert_fails("let x = matchfuzzypos(l, 'cam', test_null_dict())", 'E1297:') call assert_fails("let x = matchfuzzypos(l, 'foo', {'key' : test_null_string()})", 'E475:') @@ -178,11 +185,13 @@ func Test_matchfuzzypos() " camelcase call assert_equal([['lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'Cursor', 'CurSearch', 'CursorLine'], [[1, 2, 3], [2, 3, 4], [2, 3, 4], [6, 7, 8], [0, 1, 2], [0, 1, 2], [0, 1, 2]], [318, 311, 308, 303, 267, 264, 263]], \ matchfuzzypos(['Cursor', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'CurSearch', 'CursorLine'], 'Cur')) - + call assert_equal([['lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'Cursor', 'CurSearch', 'CursorLine'], [[1, 2, 3], [2, 3, 4], [2, 3, 4], [6, 7, 8], [0, 1, 2], [0, 1, 2], [0, 1, 2]], [318, 311, 308, 303, 267, 264, 263]], + \ matchfuzzypos(['Cursor', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'CurSearch', 'CursorLine'], 'Cur', {"camelcase": v:true})) call assert_equal([['Cursor', 'CurSearch', 'CursorLine', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor'], [[0, 1, 2], [0, 1, 2], [0, 1, 2], [1, 2, 3], [2, 3, 4], [2, 3, 4], [6, 7, 8]], [267, 264, 263, 246, 239, 236, 231]], \ matchfuzzypos(['Cursor', 'lCursor', 'shCurlyIn', 'shCurlyError', 'TracesCursor', 'CurSearch', 'CursorLine'], 'Cur', {"camelcase": v:false})) call assert_equal([['things', 'sThings', 'thisThings'], [[0, 1, 2, 3], [1, 2, 3, 4], [0, 1, 2, 7]], [333, 287, 279]], \ matchfuzzypos(['things','sThings', 'thisThings'], 'thin', {'camelcase': v:false})) + call assert_fails("let x = matchfuzzypos([], 'foo', {'camelcase': []})", 'E475: Invalid value for argument camelcase') endfunc " Test for matchfuzzy() with multibyte characters @@ -273,6 +282,7 @@ func Test_matchfuzzy_limit() call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 2})) call assert_equal(['2', '2'], x->matchfuzzy('2', #{limit: 3})) call assert_fails("call matchfuzzy(x, '2', #{limit: '2'})", 'E475:') + call assert_fails("call matchfuzzy(x, '2', #{limit: []})", 'E475:') let l = [{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}] call assert_equal([{'id': 5, 'val': 'crayon'}, {'id': 6, 'val': 'camera'}], l->matchfuzzy('c', #{text_cb: {v -> v.val}})) diff --git a/src/version.c b/src/version.c index 2f28686f9..93cda6cc9 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1219, /**/ 1218, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tucdY-0014YA-1F%40256bit.org.