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_listdict.vim b/src/testdir/test_listdict.vim
index fbb917b..5337254 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -1,7 +1,7 @@
 " Tests for the List and Dict types
 scriptencoding utf-8
 
-source vim9.vim
+import './vim9.vim' as v9
 
 func TearDown()
   " Run garbage collection after every test
@@ -50,7 +50,7 @@
       call assert_equal([2], l[-1 : -1])
       call assert_equal([1, 2], l[-2 : -1])
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let l = [1, 2]
   call assert_equal([], l[-3 : -1])
@@ -59,7 +59,7 @@
       var l = [1, 2]
       assert_equal([1, 2], l[-3 : -1])
   END
-  call CheckDefAndScriptSuccess(lines)
+  call v9.CheckDefAndScriptSuccess(lines)
 endfunc
 
 " List identity
@@ -75,7 +75,7 @@
       call assert_false(l is lx)
       call assert_true(l isnot lx)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
 " removing items with :unlet
@@ -118,7 +118,7 @@
       unlet l[-6 : 2]
       call assert_equal([3], l)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let l = [0, 1, 2, 3]
   unlet l[2:2]
@@ -131,13 +131,13 @@
       VAR l = [0, 1, 2, 3]
       unlet l[2 : 1]
   END
-  call CheckLegacyAndVim9Failure(lines, 'E684:')
+  call v9.CheckLegacyAndVim9Failure(lines, 'E684:')
 
   let lines =<< trim END
       VAR l = [0, 1, 2, 3]
       unlet l[-1 : 2]
   END
-  call CheckLegacyAndVim9Failure(lines, 'E684:')
+  call v9.CheckLegacyAndVim9Failure(lines, 'E684:')
 endfunc
 
 " assignment to a list
@@ -149,35 +149,35 @@
       LET [va, vb] = l[2 : 3]
       call assert_equal([2, 3], [va, vb])
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let lines =<< trim END
       let l = [0, 1, 2, 3]
       let [va, vb] = l
   END
-  call CheckScriptFailure(lines, 'E687:')
+  call v9.CheckScriptFailure(lines, 'E687:')
   let lines =<< trim END
       var l = [0, 1, 2, 3]
       var va = 0
       var vb = 0
       [va, vb] = l
   END
-  call CheckScriptFailure(['vim9script'] + lines, 'E687:')
-  call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
+  call v9.CheckScriptFailure(['vim9script'] + lines, 'E687:')
+  call v9.CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
 
   let lines =<< trim END
       let l = [0, 1, 2, 3]
       let [va, vb] = l[1:1]
   END
-  call CheckScriptFailure(lines, 'E688:')
+  call v9.CheckScriptFailure(lines, 'E688:')
   let lines =<< trim END
       var l = [0, 1, 2, 3]
       var va = 0
       var vb = 0
       [va, vb] = l[1 : 1]
   END
-  call CheckScriptFailure(['vim9script'] + lines, 'E688:')
-  call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
+  call v9.CheckScriptFailure(['vim9script'] + lines, 'E688:')
+  call v9.CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
 endfunc
 
 " test for range assign
@@ -189,13 +189,13 @@
       LET l[-4 : -1] = [5, 6]
       call assert_equal([5, 6], l)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let lines =<< trim END
     var l = [7]
     l[:] = ['text']
   END
-  call CheckDefAndScriptFailure(lines, 'E1012:', 2)
+  call v9.CheckDefAndScriptFailure(lines, 'E1012:', 2)
 endfunc
 
 " Test removing items in list
@@ -227,7 +227,7 @@
       call assert_equal([2, 3], remove(l, -3, -2))
       call assert_equal([1, 4], l)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   " Test invalid cases
   let l = [1, 2, 3, 4]
@@ -251,7 +251,7 @@
       call add(l, test_null_dict())
       call assert_equal([1, [2, 3], [], [], {'k': 3}, {}, {}], l)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   " weird legacy behavior
   call assert_equal(1, add(test_null_list(), 4))
@@ -271,7 +271,7 @@
       call extend(d, {'b': 'bbb', 'c': 'ccc'}, "keep")
       call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
   call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}", string(d))
@@ -320,7 +320,7 @@
       call assert_false(d is dx)
       call assert_true(d isnot dx)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
 " removing items with :unlet
@@ -331,7 +331,7 @@
       unlet d[-1]
       call assert_equal({'1': 99, '3': 33}, d)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
 " manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
@@ -405,24 +405,24 @@
       LET d._ = 2
       call assert_equal({'a': 1, '_': 2}, d)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let lines =<< trim END
     let n = 0
     let n.key = 3
   END
-  call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
+  call v9.CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
   let lines =<< trim END
     vim9script
     var n = 0
     n.key = 3
   END
-  call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
+  call v9.CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
   let lines =<< trim END
     var n = 0
     n.key = 3
   END
-  call CheckDefFailure(lines, 'E1141:')
+  call v9.CheckDefFailure(lines, 'E1141:')
 endfunc
 
 " Function in script-local List or Dict
@@ -444,55 +444,55 @@
       call assert_equal('b', remove(d, 2))
       call assert_equal({1: 'a', 3: 'c'}, d)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let lines =<< trim END
       VAR d = {1: 'a', 3: 'c'}
       call remove(d, 1, 2)
   END
-  call CheckLegacyAndVim9Failure(lines, 'E118:')
+  call v9.CheckLegacyAndVim9Failure(lines, 'E118:')
 
   let lines =<< trim END
       VAR d = {1: 'a', 3: 'c'}
       call remove(d, 'a')
   END
-  call CheckLegacyAndVim9Failure(lines, 'E716:')
+  call v9.CheckLegacyAndVim9Failure(lines, 'E716:')
 
   let lines =<< trim END
       let d = {'a-b': 55}
       echo d.a-b
   END
-  call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
+  call v9.CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
 
   let lines =<< trim END
       vim9script
       var d = {'a-b': 55}
       echo d.a-b
   END
-  call CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
+  call v9.CheckScriptFailure(lines, 'E716: Key not present in Dictionary: "a"')
 
   let lines =<< trim END
       var d = {'a-b': 55}
       echo d.a-b
   END
-  call CheckDefFailure(lines, 'E1004: White space required before and after ''-''')
+  call v9.CheckDefFailure(lines, 'E1004: White space required before and after ''-''')
 
   let lines =<< trim END
       let d = {1: 'a', 3: 'c'}
       call remove(d, [])
   END
-  call CheckScriptFailure(lines, 'E730:')
+  call v9.CheckScriptFailure(lines, 'E730:')
   let lines =<< trim END
       vim9script
       var d = {1: 'a', 3: 'c'}
       call remove(d, [])
   END
-  call CheckScriptFailure(lines, 'E1220: String or Number required for argument 2')
+  call v9.CheckScriptFailure(lines, 'E1220: String or Number required for argument 2')
   let lines =<< trim END
       var d = {1: 'a', 3: 'c'}
       call remove(d, [])
   END
-  call CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
+  call v9.CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
 endfunc
 
 " Nasty: remove func from Dict that's being called (works)
@@ -514,8 +514,8 @@
       VAR expected = 'a:' .. string(get(d, 'func'))
       call assert_equal(expected, d.func(string(remove(d, 'func'))))
   END
-  call CheckTransLegacySuccess(lines)
-  call CheckTransVim9Success(lines)
+  call v9.CheckTransLegacySuccess(lines)
+  call v9.CheckTransVim9Success(lines)
 endfunc
 
 func Test_dict_literal_keys()
@@ -535,7 +535,7 @@
       VAR dc = deepcopy(d)
       call deepcopy(d, 1)
   END
-  call CheckLegacyAndVim9Failure(lines, 'E698:')
+  call v9.CheckLegacyAndVim9Failure(lines, 'E698:')
 
   let lines =<< trim END
       VAR d = {1: 1, 2: '2'}
@@ -546,7 +546,7 @@
       VAR l3 = deepcopy(l2)
       call assert_true(l3[1] is l3[2])
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
 endfunc
@@ -631,8 +631,8 @@
         endfor
       endfor
   END
-  call CheckTransLegacySuccess(lines)
-  call CheckTransVim9Success(lines)
+  call v9.CheckTransLegacySuccess(lines)
+  call v9.CheckTransVim9Success(lines)
 
   call assert_fails("let x=islocked('a b')", 'E488:')
   let mylist = [1, 2, 3]
@@ -745,7 +745,7 @@
       unlet d.a
       call assert_equal({'b': 100}, d)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
 " filter() after lock on dict item
@@ -756,7 +756,7 @@
       call filter(d, 'v:key != "a"')
       call assert_equal({'b': 100}, d)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
 " map() after lock on dict
@@ -768,8 +768,8 @@
       call assert_equal({'a': 299, 'b': 300}, d)
   END
   " This won't work in a :def function
-  call CheckTransLegacySuccess(lines)
-  call CheckTransVim9Success(lines)
+  call v9.CheckTransLegacySuccess(lines)
+  call v9.CheckTransVim9Success(lines)
 
   " For a :def function use a global dict.
   let lines =<< trim END
@@ -780,7 +780,7 @@
       enddef
       call Delkey()
   END
-  call CheckScriptFailure(lines, 'E741:')
+  call v9.CheckScriptFailure(lines, 'E741:')
 endfunc
 
 " Lock one item in a list
@@ -792,8 +792,8 @@
       call assert_equal([299, 100, 101], l)
   END
   " This won't work in a :def function
-  call CheckTransLegacySuccess(lines)
-  call CheckTransVim9Success(lines)
+  call v9.CheckTransLegacySuccess(lines)
+  call v9.CheckTransVim9Success(lines)
 endfunc
 
 " Lock one item in a dict
@@ -805,8 +805,8 @@
       call assert_equal({'a': 299, 'b': 100, 'c': 101}, d)
   END
   " This won't work in a :def function
-  call CheckTransLegacySuccess(lines)
-  call CheckTransVim9Success(lines)
+  call v9.CheckTransLegacySuccess(lines)
+  call v9.CheckTransVim9Success(lines)
 endfunc
 
 " No extend() after lock on dict item
@@ -885,7 +885,7 @@
       lockvar! l
       call TryUnletListItem(l)
   END
-  call CheckScriptFailure(lines, 'E741:')
+  call v9.CheckScriptFailure(lines, 'E741:')
   unlet g:l
 endfunc
 
@@ -954,7 +954,7 @@
         call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l)))
       endif
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   call assert_fails('call reverse("")', 'E899:')
   call assert_fails('call uniq([1, 2], {x, y -> []})', 'E745:')
@@ -997,7 +997,7 @@
       call assert_equal('Å,s,t,r,ö,m', reduce('Åström', LSTART acc, val LMIDDLE acc .. ',' .. val LEND))
       call assert_equal(',a,b,c', reduce('abc', LSTART acc, val LMIDDLE acc .. ',' .. val LEND, test_null_string()))
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   call assert_equal({'x': 1, 'y': 1, 'z': 1 }, ['x', 'y', 'z']->reduce({ acc, val -> extend(acc, { val: 1 }) }, {}))
   vim9 assert_equal({'x': 1, 'y': 1, 'z': 1 }, ['x', 'y', 'z']->reduce((acc, val) => extend(acc, {[val]: 1 }), {}))
@@ -1055,7 +1055,7 @@
       call assert_equal(['', 'a', '', 'b', '', 'c', ''], split('abc', '\zs', 1))
       call assert_equal(['abc'], split('abc', '\\%('))
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   call assert_fails("call split('abc', [])", 'E730:')
   call assert_fails("call split('abc', 'b', [])", 'E745:')
@@ -1072,7 +1072,7 @@
       call assert_false(l != deepcopy(l))
       call assert_false(d != deepcopy(d))
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   " comparison errors
   call assert_fails('echo [1, 2] =~ {}', 'E691:')
@@ -1093,7 +1093,7 @@
       call assert_true(l == lcopy)
       call assert_true(dict4 == dict4copy)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
 " Test for extending lists and dictionaries
@@ -1130,7 +1130,7 @@
       call extend(l, [4, 5, 6], -3)
       call assert_equal([4, 5, 6, 1, 2,  3], l)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let l = [1, 2, 3]
   call assert_fails("call extend(l, [4, 5, 6], 4)", 'E684:')
@@ -1159,7 +1159,7 @@
       call extend(d, {'b': 0, 'c': 'C'}, "keep")
       call assert_equal({'a': 'A', 'b': 9, 'c': 'C'}, d)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let d = {'a': 'A', 'b': 'B'}
   call assert_fails("call extend(d, {'b': 0, 'c':'C'}, 'error')", 'E737:')
@@ -1191,7 +1191,7 @@
       call extend(l, l, 3)
       call assert_equal([1, 5, 7, 1, 5, 7], l)
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 endfunc
 
 func Test_listdict_extendnew()
@@ -1318,30 +1318,30 @@
 
 " List and dict indexing tests
 func Test_listdict_index()
-  call CheckLegacyAndVim9Failure(['echo function("min")[0]'], 'E695:')
-  call CheckLegacyAndVim9Failure(['echo v:true[0]'], 'E909:')
-  call CheckLegacyAndVim9Failure(['echo v:null[0]'], 'E909:')
-  call CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d.'], ['E15:', 'E1127:', 'E15:'])
-  call CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d[1 : 2]'], 'E719:')
+  call v9.CheckLegacyAndVim9Failure(['echo function("min")[0]'], 'E695:')
+  call v9.CheckLegacyAndVim9Failure(['echo v:true[0]'], 'E909:')
+  call v9.CheckLegacyAndVim9Failure(['echo v:null[0]'], 'E909:')
+  call v9.CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d.'], ['E15:', 'E1127:', 'E15:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR d = {"k": 10}', 'echo d[1 : 2]'], 'E719:')
 
   call assert_fails("let v = [4, 6][{-> 1}]", 'E729:')
-  call CheckDefAndScriptFailure(['var v = [4, 6][() => 1]'], ['E1012', 'E703:'])
+  call v9.CheckDefAndScriptFailure(['var v = [4, 6][() => 1]'], ['E1012', 'E703:'])
 
-  call CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : []]'], ['E730:', 'E1012:', 'E730:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : []]'], ['E730:', 'E1012:', 'E730:'])
 
   call assert_fails("let v = range(5)[2:{-> 2}(]", ['E15:', 'E116:'])
-  call CheckDefAndScriptFailure(['var v = range(5)[2 : () => 2(]'], 'E15:')
+  call v9.CheckDefAndScriptFailure(['var v = range(5)[2 : () => 2(]'], 'E15:')
 
-  call CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : 3'], ['E111:', 'E1097:', 'E111:'])
-  call CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, 10)'], 'E684:')
-  call CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, -10)'], 'E684:')
-  call CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, [])'], ['E745:', 'E1013:', 'E1210:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR v = range(5)[2 : 3'], ['E111:', 'E1097:', 'E111:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, 10)'], 'E684:')
+  call v9.CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, -10)'], 'E684:')
+  call v9.CheckLegacyAndVim9Failure(['VAR l = insert([1, 2, 3], 4, [])'], ['E745:', 'E1013:', 'E1210:'])
 
-  call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[i] = 3'], ['E121:', 'E1001:', 'E121:'])
-  call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[1.1] = 4'], ['E805:', 'E1012:', 'E805:'])
-  call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: i] = [4, 5]'], ['E121:', 'E1001:', 'E121:'])
-  call CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: 3.2] = [4, 5]'], ['E805:', 'E1012:', 'E805:'])
-  call CheckLegacyAndVim9Failure(['VAR t = test_unknown()', 'echo t[0]'], 'E685:')
+  call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[i] = 3'], ['E121:', 'E1001:', 'E121:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[1.1] = 4'], ['E805:', 'E1012:', 'E805:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: i] = [4, 5]'], ['E121:', 'E1001:', 'E121:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: 3.2] = [4, 5]'], ['E805:', 'E1012:', 'E805:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR t = test_unknown()', 'echo t[0]'], 'E685:')
 endfunc
 
 " Test for a null list
@@ -1379,7 +1379,7 @@
       call assert_equal([], sort(l))
       call assert_equal('[]', string(l))
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let l = test_null_list()
   call assert_equal([], extend(l, l, 0))
@@ -1420,7 +1420,7 @@
       call assert_equal(0, remove(test_null_dict(), 'k'))
       call assert_equal('{}', string(d))
   END
-  call CheckLegacyAndVim9Success(lines)
+  call v9.CheckLegacyAndVim9Success(lines)
 
   let d = test_null_dict()
   call assert_equal({}, extend(d, d, 'keep'))