patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Problem: Vim9: finding global function without g: prefix but not finding
global variable is inconsistent.
Solution: Require using g: for a global function. Change the vim9.vim
script into a Vim9 script with exports. Fix that import in legacy
script does not work.
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index d333090..5fbdef8 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -1,9 +1,9 @@
" Test the :disassemble command, and compilation as a side effect
source check.vim
-source vim9.vim
+import './vim9.vim' as v9
-func NotCompiled()
+func s:NotCompiled()
echo "not"
endfunc
@@ -312,7 +312,7 @@
'2 RETURN void',
res)
END
- CheckScriptSuccess(lines)
+ v9.CheckScriptSuccess(lines)
delete('Xdir', 'rf')
&rtp = save_rtp
@@ -690,22 +690,22 @@
res)
enddef
-def FuncWithArg(arg: any)
+def s:FuncWithArg(arg: any)
echo arg
enddef
-func UserFunc()
+func s:UserFunc()
echo 'nothing'
endfunc
-func UserFuncWithArg(arg)
+func s:UserFuncWithArg(arg)
echo a:arg
endfunc
def s:ScriptFuncCall(): string
changenr()
char2nr("abc")
- Test_disassemble_new()
+ g:Test_disassemble_new()
FuncWithArg(343)
ScriptFuncNew()
s:ScriptFuncNew()
@@ -728,12 +728,12 @@
'\d PUSHS "abc"\_s*' ..
'\d BCALL char2nr(argc 1)\_s*' ..
'\d DROP\_s*' ..
- 'Test_disassemble_new()\_s*' ..
+ 'g:Test_disassemble_new()\_s*' ..
'\d DCALL Test_disassemble_new(argc 0)\_s*' ..
'\d DROP\_s*' ..
'FuncWithArg(343)\_s*' ..
'\d\+ PUSHNR 343\_s*' ..
- '\d\+ DCALL FuncWithArg(argc 1)\_s*' ..
+ '\d\+ DCALL <SNR>\d\+_FuncWithArg(argc 1)\_s*' ..
'\d\+ DROP\_s*' ..
'ScriptFuncNew()\_s*' ..
'\d\+ DCALL <SNR>\d\+_ScriptFuncNew(argc 0)\_s*' ..
@@ -742,11 +742,11 @@
'\d\+ DCALL <SNR>\d\+_ScriptFuncNew(argc 0)\_s*' ..
'\d\+ DROP\_s*' ..
'UserFunc()\_s*' ..
- '\d\+ UCALL UserFunc(argc 0)\_s*' ..
+ '\d\+ UCALL <80><fd>R\d\+_UserFunc(argc 0)\_s*' ..
'\d\+ DROP\_s*' ..
'UserFuncWithArg("foo")\_s*' ..
'\d\+ PUSHS "foo"\_s*' ..
- '\d\+ UCALL UserFuncWithArg(argc 1)\_s*' ..
+ '\d\+ UCALL <80><fd>R\d\+_UserFuncWithArg(argc 1)\_s*' ..
'\d\+ DROP\_s*' ..
'var FuncRef = function("UserFunc")\_s*' ..
'\d\+ PUSHS "UserFunc"\_s*' ..
@@ -811,7 +811,7 @@
def EchoArg(arg: string): string
return arg
enddef
-def RefThis(): func
+def s:RefThis(): func
return function('EchoArg')
enddef
def s:ScriptPCall()
@@ -822,7 +822,7 @@
var res = execute('disass s:ScriptPCall')
assert_match('<SNR>\d\+_ScriptPCall\_s*' ..
'RefThis()("text")\_s*' ..
- '\d DCALL RefThis(argc 0)\_s*' ..
+ '\d DCALL <SNR>\d\+_RefThis(argc 0)\_s*' ..
'\d PUSHS "text"\_s*' ..
'\d PCALL top (argc 1)\_s*' ..
'\d PCALL end\_s*' ..
@@ -1116,7 +1116,7 @@
instr)
enddef
-def WithLambda(): string
+def s:WithLambda(): string
var F = (a) => "X" .. a .. "X"
return F("x")
enddef
@@ -1149,7 +1149,7 @@
instr)
enddef
-def LambdaWithType(): number
+def s:LambdaWithType(): number
var Ref = (a: number) => a + 10
return Ref(g:value)
enddef
@@ -1210,7 +1210,7 @@
instr)
enddef
-def AndOr(arg: any): string
+def s:AndOr(arg: any): string
if arg == 1 && arg != 2 || arg == 4
return 'yes'
endif
@@ -1239,7 +1239,7 @@
instr)
enddef
-def AndConstant(arg: any): string
+def s:AndConstant(arg: any): string
if true && arg
return "yes"
endif
@@ -1271,7 +1271,7 @@
instr)
enddef
-def ForLoop(): list<number>
+def s:ForLoop(): list<number>
var res: list<number>
for i in range(3)
res->add(i)
@@ -1304,7 +1304,7 @@
instr)
enddef
-def ForLoopEval(): string
+def s:ForLoopEval(): string
var res = ""
for str in eval('["one", "two"]')
res ..= str
@@ -1340,7 +1340,7 @@
instr)
enddef
-def ForLoopUnpack()
+def s:ForLoopUnpack()
for [x1, x2] in [[1, 2], [3, 4]]
echo x1 x2
endfor
@@ -1373,7 +1373,7 @@
instr)
enddef
-def ForLoopContinue()
+def s:ForLoopContinue()
for nr in [1, 2]
try
echo "ok"
@@ -1432,7 +1432,7 @@
let g:number = 42
-def TypeCast()
+def s:TypeCast()
var l: list<number> = [23, <number>g:number]
enddef
@@ -1450,7 +1450,7 @@
instr)
enddef
-def Computing()
+def s:Computing()
var nr = 3
var nrres = nr + 7
nrres = nr - 7
@@ -1525,7 +1525,7 @@
endif
enddef
-def AddListBlob()
+def s:AddListBlob()
var reslist = [1, 2] + [3, 4]
var resblob = 0z1122 + 0z3344
enddef
@@ -1551,7 +1551,7 @@
enddef
let g:aa = 'aa'
-def ConcatString(): string
+def s:ConcatString(): string
var res = g:aa .. "bb"
return res
enddef
@@ -1569,7 +1569,7 @@
assert_equal('aabb', ConcatString())
enddef
-def StringIndex(): string
+def s:StringIndex(): string
var s = "abcd"
var res = s[1]
return res
@@ -1590,7 +1590,7 @@
assert_equal('b', StringIndex())
enddef
-def StringSlice(): string
+def s:StringSlice(): string
var s = "abcd"
var res = s[1 : 8]
return res
@@ -1612,7 +1612,7 @@
assert_equal('bcd', StringSlice())
enddef
-def ListIndex(): number
+def s:ListIndex(): number
var l = [1, 2, 3]
var res = l[1]
return res
@@ -1636,7 +1636,7 @@
assert_equal(2, ListIndex())
enddef
-def ListSlice(): list<number>
+def s:ListSlice(): list<number>
var l = [1, 2, 3]
var res = l[1 : 8]
return res
@@ -1661,7 +1661,7 @@
assert_equal([2, 3], ListSlice())
enddef
-def DictMember(): number
+def s:DictMember(): number
var d = {item: 1}
var res = d.item
res = d["item"]
@@ -1692,7 +1692,7 @@
enddef
let somelist = [1, 2, 3, 4, 5]
-def AnyIndex(): number
+def s:AnyIndex(): number
var res = g:somelist[2]
return res
enddef
@@ -1713,7 +1713,7 @@
assert_equal(3, AnyIndex())
enddef
-def AnySlice(): list<number>
+def s:AnySlice(): list<number>
var res = g:somelist[1 : 3]
return res
enddef
@@ -1735,7 +1735,7 @@
assert_equal([2, 3, 4], AnySlice())
enddef
-def NegateNumber(): number
+def s:NegateNumber(): number
g:nr = 9
var plus = +g:nr
var minus = -g:nr
@@ -1761,7 +1761,7 @@
assert_equal(-9, NegateNumber())
enddef
-def InvertBool(): bool
+def s:InvertBool(): bool
var flag = true
var invert = !flag
var res = !!flag
@@ -1786,7 +1786,7 @@
assert_equal(true, InvertBool())
enddef
-def ReturnBool(): bool
+def s:ReturnBool(): bool
var one = 1
var zero = 0
var none: number
@@ -1818,7 +1818,7 @@
assert_equal(true, InvertBool())
enddef
-def AutoInit()
+def s:AutoInit()
var t: number
t = 1
t = 0