mirror of
https://github.com/vim/vim.git
synced 2025-10-03 05:14:07 -04:00
patch 8.2.4260: Vim9: can still use a global function without g:
Problem: Vim9: can still use a global function without g: at the script level. Solution: Also check for g: at the script level. (issue #9637)
This commit is contained in:
@@ -61,12 +61,17 @@ def Test_expr1_trinary()
|
||||
var RetThat: func = g:atrue ? RetOne : RetTwo
|
||||
assert_equal(function('len'), RetThat)
|
||||
|
||||
var X = FuncOne
|
||||
var Y = FuncTwo
|
||||
var Z = g:cond ? FuncOne : FuncTwo
|
||||
var X = g:FuncOne
|
||||
var Y = g:FuncTwo
|
||||
var Z = g:cond ? g:FuncOne : g:FuncTwo
|
||||
assert_equal(123, Z(3))
|
||||
END
|
||||
v9.CheckDefAndScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
var Z = g:cond ? FuncOne : FuncTwo
|
||||
END
|
||||
v9.CheckDefAndScriptFailure(lines, ['E1001: Variable not found: FuncOne', 'E121: Undefined variable: FuncTwo'])
|
||||
enddef
|
||||
|
||||
def Test_expr1_trinary_vimscript()
|
||||
@@ -209,9 +214,9 @@ func Test_expr1_trinary_fails()
|
||||
|
||||
" missing argument detected even when common type is used
|
||||
call v9.CheckDefAndScriptFailure([
|
||||
\ 'var X = FuncOne',
|
||||
\ 'var Y = FuncTwo',
|
||||
\ 'var Z = g:cond ? FuncOne : FuncTwo',
|
||||
\ 'var X = g:FuncOne',
|
||||
\ 'var Y = g:FuncTwo',
|
||||
\ 'var Z = g:cond ? g:FuncOne : g:FuncTwo',
|
||||
\ 'Z()'], 'E119:', 4)
|
||||
endfunc
|
||||
|
||||
@@ -2334,7 +2339,7 @@ def Test_expr8_funcref()
|
||||
def Test()
|
||||
var Ref = g:GlobalFunc
|
||||
assert_equal('global', Ref())
|
||||
Ref = GlobalFunc
|
||||
Ref = g:GlobalFunc
|
||||
assert_equal('global', Ref())
|
||||
|
||||
Ref = s:ScriptFunc
|
||||
@@ -3083,12 +3088,12 @@ def Test_expr8_call()
|
||||
v9.CheckDefAndScriptFailure(["var Ref = function('len' [1, 2])"], ['E1123:', 'E116:'], 1)
|
||||
enddef
|
||||
|
||||
def g:ExistingGloba(): string
|
||||
def g:ExistingGlobal(): string
|
||||
return 'existing'
|
||||
enddef
|
||||
|
||||
def Test_expr8_call_global()
|
||||
assert_equal('existing', g:ExistingGloba())
|
||||
assert_equal('existing', g:ExistingGlobal())
|
||||
|
||||
def g:DefinedLater(): string
|
||||
return 'later'
|
||||
|
Reference in New Issue
Block a user