vim-patch:9.0.1508: catch does not work when lines are joined with a newline

Problem:    Catch does not work when lines are joined with a newline.
Solution:   Set "nextcmd" appropriately. (closes vim/vim#12348)

f2588b6fc9
This commit is contained in:
zeertzjq
2023-05-06 07:44:34 +08:00
parent ad7f9a701c
commit 6b912dec8e
2 changed files with 38 additions and 5 deletions

View File

@@ -2368,11 +2368,14 @@ int eval0(char *arg, typval_T *rettv, exarg_T *eap, evalarg_T *const evalarg)
}
}
// Some of the expression may not have been consumed. Do not check for
// a next command to avoid more errors, unless "|" is following, which
// could only be a command separator.
if (eap != NULL && skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|') {
eap->nextcmd = check_nextcmd(p);
if (eap != NULL && p != NULL) {
// Some of the expression may not have been consumed.
// Only execute a next command if it cannot be a "||" operator.
// The next command may be "catch".
char *nextcmd = check_nextcmd(p);
if (nextcmd != NULL && *nextcmd != '|') {
eap->nextcmd = nextcmd;
}
}
return FAIL;
}

View File

@@ -2220,6 +2220,36 @@ func Test_BufEnter_exception()
%bwipe!
endfunc
" Test for using try/catch when lines are joined by "|" or "\n" {{{1
func Test_try_catch_nextcmd()
func Throw()
throw "Failure"
endfunc
let lines =<< trim END
try
let s:x = Throw()
catch
let g:caught = 1
endtry
END
let g:caught = 0
call execute(lines)
call assert_equal(1, g:caught)
let g:caught = 0
call execute(join(lines, '|'))
call assert_equal(1, g:caught)
let g:caught = 0
call execute(join(lines, "\n"))
call assert_equal(1, g:caught)
unlet g:caught
delfunc Throw
endfunc
" Test for using try/catch in a user command with a failing expression {{{1
func Test_user_command_try_catch()
let lines =<< trim END