1
0
forked from aniani/vim

patch 8.2.2617: Vim9: script variable in block not found by function

Problem:    Vim9: script variable in a block scope not found by a nested
            function.
Solution:   Copy the block scope IDs before compiling the function.
This commit is contained in:
Bram Moolenaar
2021-03-17 18:42:08 +01:00
parent 3e1916947d
commit 8863bda25d
4 changed files with 38 additions and 16 deletions

View File

@@ -393,7 +393,6 @@ def Test_nested_function()
CheckDefFailure(lines, 'E1117:')
# nested function inside conditional
# TODO: should it work when "thecount" is inside the "if"?
lines =<< trim END
vim9script
var thecount = 0
@@ -411,6 +410,25 @@ def Test_nested_function()
assert_equal(2, Test())
END
CheckScriptSuccess(lines)
# also works when "thecount" is inside the "if" block
lines =<< trim END
vim9script
if true
var thecount = 0
def Test(): number
def TheFunc(): number
thecount += 1
return thecount
enddef
return TheFunc()
enddef
endif
defcompile
assert_equal(1, Test())
assert_equal(2, Test())
END
CheckScriptSuccess(lines)
enddef
def Test_not_nested_function()