1
0
forked from aniani/vim

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.
This commit is contained in:
Bram Moolenaar
2022-01-29 21:45:34 +00:00
parent 135e15251e
commit 62aec93bfd
34 changed files with 3212 additions and 3176 deletions

View File

@@ -2,7 +2,7 @@
source view_util.vim
source check.vim
source vim9.vim
import './vim9.vim' as v9
let s:imactivatefunc_called = 0
let s:imstatusfunc_called = 0
@@ -165,28 +165,28 @@ func Test_imactivatefunc_imstatusfunc_callback()
normal! i
#" Test for using a lambda function
VAR optval = "LSTART a LMIDDLE IMactivatefunc1(a) LEND"
VAR optval = "LSTART a LMIDDLE g:IMactivatefunc1(a) LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set imactivatefunc=" .. optval
LET optval = "LSTART LMIDDLE IMstatusfunc1() LEND"
LET optval = "LSTART LMIDDLE g:IMstatusfunc1() LEND"
LET optval = substitute(optval, ' ', '\\ ', 'g')
exe "set imstatusfunc=" .. optval
normal! i
#" Set 'imactivatefunc' and 'imstatusfunc' to a lambda expression
LET &imactivatefunc = LSTART a LMIDDLE IMactivatefunc1(a) LEND
LET &imstatusfunc = LSTART LMIDDLE IMstatusfunc1() LEND
LET &imactivatefunc = LSTART a LMIDDLE g:IMactivatefunc1(a) LEND
LET &imstatusfunc = LSTART LMIDDLE g:IMstatusfunc1() LEND
normal! i
#" Set 'imactivatefunc' and 'imstatusfunc' to a string(lambda expression)
LET &imactivatefunc = 'LSTART a LMIDDLE IMactivatefunc1(a) LEND'
LET &imstatusfunc = 'LSTART LMIDDLE IMstatusfunc1() LEND'
LET &imactivatefunc = 'LSTART a LMIDDLE g:IMactivatefunc1(a) LEND'
LET &imstatusfunc = 'LSTART LMIDDLE g:IMstatusfunc1() LEND'
normal! i
#" Set 'imactivatefunc' 'imstatusfunc' to a variable with a lambda
#" expression
VAR Lambda1 = LSTART a LMIDDLE IMactivatefunc1(a) LEND
VAR Lambda2 = LSTART LMIDDLE IMstatusfunc1() LEND
VAR Lambda1 = LSTART a LMIDDLE g:IMactivatefunc1(a) LEND
VAR Lambda2 = LSTART LMIDDLE g:IMstatusfunc1() LEND
LET &imactivatefunc = Lambda1
LET &imstatusfunc = Lambda2
normal! i
@@ -223,7 +223,7 @@ func Test_imactivatefunc_imstatusfunc_callback()
call assert_equal(14, g:IMactivatefunc_called)
call assert_equal(28, g:IMstatusfunc_called)
END
call CheckLegacyAndVim9Success(lines)
call v9.CheckLegacyAndVim9Success(lines)
" Using Vim9 lambda expression in legacy context should fail
set imactivatefunc=(a)\ =>\ IMactivatefunc1(a)
@@ -285,7 +285,7 @@ func Test_imactivatefunc_imstatusfunc_callback()
set imactivatefunc=
set imstatusfunc=
END
call CheckScriptSuccess(lines)
call v9.CheckScriptSuccess(lines)
" cleanup
set iminsert=0