Patch 9.0.1508
Problem: Catch does not work when lines are joined with a newline.
Solution: Set "nextcmd" appropriately. (closes #12348)
Files: src/eval.c, src/testdir/test_trycatch.vim
*** ../vim-9.0.1507/src/eval.c 2023-05-02 16:25:35.630819728 +0100
--- src/eval.c 2023-05-05 17:20:29.545858434 +0100
***************
*** 2699,2710 ****
semsg(_(e_invalid_expression_str), arg);
}
! // 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 && p != NULL
! && skipwhite(p)[0] == '|' && skipwhite(p)[1] != '|')
! eap->nextcmd = check_nextcmd(p);
return FAIL;
}
--- 2699,2713 ----
semsg(_(e_invalid_expression_str), arg);
}
! 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_u *nextcmd = check_nextcmd(p);
! if (nextcmd != NULL && *nextcmd != '|')
! eap->nextcmd = nextcmd;
! }
return FAIL;
}
*** ../vim-9.0.1507/src/testdir/test_trycatch.vim 2022-10-15
20:52:22.563752598 +0100
--- src/testdir/test_trycatch.vim 2023-05-05 17:16:11.374443419 +0100
***************
*** 2220,2225 ****
--- 2220,2255 ----
%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
*** ../vim-9.0.1507/src/version.c 2023-05-04 18:58:18.410209481 +0100
--- src/version.c 2023-05-05 17:18:08.442145268 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1508,
/**/
--
Normal people believe that if it ain't broke, don't fix it. Engineers believe
that if it ain't broke, it doesn't have enough features yet.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20230505162257.E52A11C1B32%40moolenaar.net.