Skip to content

Commit 5671f3f

Browse files
committed
patch 8.2.3299: Vim9: exists() does not handle much at compile time
Problem: Vim9: exists() does not handle much at compile time. Solution: Handle variable names. (closes #8688)
1 parent 6f6d58c commit 5671f3f

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/evalfunc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,7 +3552,14 @@ f_exists(typval_T *argvars, typval_T *rettv)
35523552
}
35533553
else if (*p == '*') // internal or user defined function
35543554
{
3555+
int save_version = current_sctx.sc_version;
3556+
3557+
// Vim9 script assumes a function is script-local, but here we want to
3558+
// find any matching function.
3559+
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
3560+
current_sctx.sc_version = SCRIPT_VERSION_MAX;
35553561
n = function_exists(p + 1, FALSE);
3562+
current_sctx.sc_version = save_version;
35563563
}
35573564
else if (*p == '?') // internal function only
35583565
{

src/testdir/test_vim9_builtin.vim

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ def Test_exepath()
787787
CheckDefExecFailure(['echo exepath("")'], 'E1175:')
788788
enddef
789789

790+
command DoSomeCommand let g:didSomeCommand = 4
791+
790792
def Test_exists()
791793
CheckDefAndScriptFailure2(['exists(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
792794
call assert_equal(1, exists('&tabstop'))
@@ -809,6 +811,26 @@ def Test_exists()
809811
else
810812
assert_report('tabstop option not existing?')
811813
endif
814+
815+
if exists(':DoSomeCommand') >= 2
816+
DoSomeCommand
817+
endif
818+
assert_equal(4, g:didSomeCommand)
819+
if exists(':NoSuchCommand') >= 2
820+
NoSuchCommand
821+
endif
822+
823+
var found = false
824+
if exists('*CheckScriptSuccess')
825+
found = true
826+
endif
827+
assert_true(found)
828+
if exists('*NoSuchFunction')
829+
NoSuchFunction()
830+
endif
831+
if exists('*no_such_function')
832+
no_such_function()
833+
endif
812834
enddef
813835

814836
def Test_expand()
@@ -2948,7 +2970,7 @@ def Test_setreg()
29482970
assert_fails('setreg("ab", 0)', 'E1162:')
29492971
CheckDefAndScriptFailure2(['setreg(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
29502972
CheckDefAndScriptFailure2(['setreg("a", "b", 3)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
2951-
enddef
2973+
enddef
29522974

29532975
def Test_settabvar()
29542976
CheckDefAndScriptFailure2(['settabvar("a", "b", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3299,
758760
/**/
759761
3298,
760762
/**/

src/vim9compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,8 +3417,8 @@ compile_call(
34173417
s = skipwhite(s);
34183418
if (*s == ')' && argvars[0].v_type == VAR_STRING
34193419
&& ((is_has && !dynamic_feature(argvars[0].vval.v_string))
3420-
|| (!is_has && (*argvars[0].vval.v_string == '+'
3421-
|| *argvars[0].vval.v_string == '&'))))
3420+
|| (!is_has && vim_strchr((char_u *)"+&:*",
3421+
*argvars[0].vval.v_string))))
34223422
{
34233423
typval_T *tv = &ppconst->pp_tv[ppconst->pp_used];
34243424

0 commit comments

Comments
 (0)