mirror of
https://github.com/vim/vim.git
synced 2025-10-03 05:14:07 -04:00
patch 8.2.4071: Vim9: no detection of return in try/endtry
Problem: Vim9: no detection of return in try/endtry. (Dominique Pellé) Solution: Check if any of the blocks inside try/endtry did not end in return.
This commit is contained in:
@@ -667,7 +667,6 @@ def Test_try_catch_throw()
|
||||
finally
|
||||
return 6
|
||||
endtry
|
||||
return -1
|
||||
enddef
|
||||
assert_equal(6, ReturnInFinally())
|
||||
|
||||
@@ -708,6 +707,64 @@ def Test_try_catch_throw()
|
||||
CheckDefAndScriptSuccess(lines)
|
||||
enddef
|
||||
|
||||
def Test_try_ends_in_return()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
def Foo(): string
|
||||
try
|
||||
return 'foo'
|
||||
catch
|
||||
return 'caught'
|
||||
endtry
|
||||
enddef
|
||||
assert_equal('foo', Foo())
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
def Foo(): string
|
||||
try
|
||||
return 'foo'
|
||||
catch
|
||||
return 'caught'
|
||||
endtry
|
||||
echo 'notreached'
|
||||
enddef
|
||||
assert_equal('foo', Foo())
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1095:')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
def Foo(): string
|
||||
try
|
||||
return 'foo'
|
||||
catch /x/
|
||||
return 'caught'
|
||||
endtry
|
||||
enddef
|
||||
assert_equal('foo', Foo())
|
||||
END
|
||||
CheckScriptFailure(lines, 'E1027:')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
def Foo(): string
|
||||
try
|
||||
echo 'foo'
|
||||
catch
|
||||
echo 'caught'
|
||||
finally
|
||||
return 'done'
|
||||
endtry
|
||||
enddef
|
||||
assert_equal('done', Foo())
|
||||
END
|
||||
CheckScriptSuccess(lines)
|
||||
|
||||
enddef
|
||||
|
||||
def Test_try_in_catch()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
|
Reference in New Issue
Block a user