mirror of
https://github.com/vim/vim.git
synced 2025-09-30 04:44:14 -04:00
patch 8.2.0753: Vim9: expressions are evaluated in the discovery phase
Problem: Vim9: expressions are evaluated in the discovery phase. Solution: Bail out if an expression is not a constant. Require a type for declared constants.
This commit is contained in:
@@ -494,7 +494,7 @@ let s:export_script_lines =<< trim END
|
||||
def Concat(arg: string): string
|
||||
return name .. arg
|
||||
enddef
|
||||
let g:result = Concat('bie')
|
||||
let g:result: string = Concat('bie')
|
||||
let g:localname = name
|
||||
|
||||
export const CONST = 1234
|
||||
@@ -1633,7 +1633,7 @@ def Test_vim9_comment_not_compiled()
|
||||
CheckScriptFailure([
|
||||
'vim9script',
|
||||
'let g:var = 123',
|
||||
'unlet g:var# comment',
|
||||
'unlet g:var# comment1',
|
||||
], 'E108:')
|
||||
|
||||
CheckScriptFailure([
|
||||
@@ -1643,7 +1643,7 @@ def Test_vim9_comment_not_compiled()
|
||||
|
||||
CheckScriptSuccess([
|
||||
'vim9script',
|
||||
'if 1 # comment',
|
||||
'if 1 # comment2',
|
||||
' echo "yes"',
|
||||
'elseif 2 #comment',
|
||||
' echo "no"',
|
||||
@@ -1652,14 +1652,14 @@ def Test_vim9_comment_not_compiled()
|
||||
|
||||
CheckScriptFailure([
|
||||
'vim9script',
|
||||
'if 1# comment',
|
||||
'if 1# comment3',
|
||||
' echo "yes"',
|
||||
'endif',
|
||||
], 'E15:')
|
||||
|
||||
CheckScriptFailure([
|
||||
'vim9script',
|
||||
'if 0 # comment',
|
||||
'if 0 # comment4',
|
||||
' echo "yes"',
|
||||
'elseif 2#comment',
|
||||
' echo "no"',
|
||||
@@ -1668,23 +1668,18 @@ def Test_vim9_comment_not_compiled()
|
||||
|
||||
CheckScriptSuccess([
|
||||
'vim9script',
|
||||
'let # comment',
|
||||
'let v = 1 # comment5',
|
||||
])
|
||||
|
||||
CheckScriptFailure([
|
||||
'vim9script',
|
||||
'let# comment',
|
||||
], 'E121:')
|
||||
|
||||
CheckScriptSuccess([
|
||||
'vim9script',
|
||||
'let v:version # comment',
|
||||
])
|
||||
'let v = 1# comment6',
|
||||
], 'E15:')
|
||||
|
||||
CheckScriptFailure([
|
||||
'vim9script',
|
||||
'let v:version# comment',
|
||||
], 'E121:')
|
||||
'let v:version',
|
||||
], 'E1091:')
|
||||
|
||||
CheckScriptSuccess([
|
||||
'vim9script',
|
||||
@@ -1722,6 +1717,41 @@ def Test_finish()
|
||||
delete('Xfinished')
|
||||
enddef
|
||||
|
||||
def Test_let_func_call()
|
||||
let lines =<< trim END
|
||||
vim9script
|
||||
func GetValue()
|
||||
if exists('g:count')
|
||||
let g:count += 1
|
||||
else
|
||||
let g:count = 1
|
||||
endif
|
||||
return 'this'
|
||||
endfunc
|
||||
let val: string = GetValue()
|
||||
END
|
||||
writefile(lines, 'Xfinished')
|
||||
source Xfinished
|
||||
assert_equal(1, g:count)
|
||||
|
||||
unlet g:count
|
||||
delete('Xfinished')
|
||||
enddef
|
||||
|
||||
def Test_let_missing_type()
|
||||
let lines =<< trim END
|
||||
vim9script
|
||||
func GetValue()
|
||||
return 'this'
|
||||
endfunc
|
||||
let val = GetValue()
|
||||
END
|
||||
writefile(lines, 'Xfinished')
|
||||
assert_fails('source Xfinished', 'E1091:')
|
||||
|
||||
delete('Xfinished')
|
||||
enddef
|
||||
|
||||
" Keep this last, it messes up highlighting.
|
||||
def Test_substitute_cmd()
|
||||
new
|
||||
|
Reference in New Issue
Block a user