mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
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 #12348)
This commit is contained in:
15
src/eval.c
15
src/eval.c
@@ -2699,12 +2699,15 @@ eval0_retarg(
|
|||||||
semsg(_(e_invalid_expression_str), arg);
|
semsg(_(e_invalid_expression_str), arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some of the expression may not have been consumed. Do not check for
|
if (eap != NULL && p != NULL)
|
||||||
// a next command to avoid more errors, unless "|" is following, which
|
{
|
||||||
// could only be a command separator.
|
// Some of the expression may not have been consumed.
|
||||||
if (eap != NULL && p != NULL
|
// Only execute a next command if it cannot be a "||" operator.
|
||||||
&& skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|')
|
// The next command may be "catch".
|
||||||
eap->nextcmd = check_nextcmd(p);
|
char_u *nextcmd = check_nextcmd(p);
|
||||||
|
if (nextcmd != NULL && *nextcmd != '|')
|
||||||
|
eap->nextcmd = nextcmd;
|
||||||
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2220,6 +2220,36 @@ func Test_BufEnter_exception()
|
|||||||
%bwipe!
|
%bwipe!
|
||||||
endfunc
|
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
|
" Test for using try/catch in a user command with a failing expression {{{1
|
||||||
func Test_user_command_try_catch()
|
func Test_user_command_try_catch()
|
||||||
let lines =<< trim END
|
let lines =<< trim END
|
||||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1508,
|
||||||
/**/
|
/**/
|
||||||
1507,
|
1507,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user