Patch 8.2.1063
Problem: Vim9: no line break allowed before || or &&.
Solution: Check for operator after line break.
Files: src/eval.c, src/testdir/test_vim9_expr.vim
*** ../vim-8.2.1062/src/eval.c 2020-06-26 21:28:22.008863411 +0200
--- src/eval.c 2020-06-26 21:32:13.304254326 +0200
***************
*** 1991,1996 ****
--- 1991,1998 ----
static int
eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
{
+ char_u *p;
+ int getnext;
typval_T var2;
long result;
int first;
***************
*** 2007,2018 ****
*/
first = TRUE;
result = FALSE;
! while ((*arg)[0] == '|' && (*arg)[1] == '|')
{
evalarg_T nested_evalarg;
int evaluate;
int orig_flags;
if (evalarg == NULL)
{
CLEAR_FIELD(nested_evalarg);
--- 2009,2024 ----
*/
first = TRUE;
result = FALSE;
! p = eval_next_non_blank(*arg, evalarg, &getnext);
! while (p[0] == '|' && p[1] == '|')
{
evalarg_T nested_evalarg;
int evaluate;
int orig_flags;
+ if (getnext)
+ *arg = eval_next_line(evalarg);
+
if (evalarg == NULL)
{
CLEAR_FIELD(nested_evalarg);
***************
*** 2061,2066 ****
--- 2067,2074 ----
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = result;
}
+
+ p = eval_next_non_blank(*arg, evalarg, &getnext);
}
return OK;
***************
*** 2078,2083 ****
--- 2086,2093 ----
static int
eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
{
+ char_u *p;
+ int getnext;
typval_T var2;
long result;
int first;
***************
*** 2094,2105 ****
*/
first = TRUE;
result = TRUE;
! while ((*arg)[0] == '&' && (*arg)[1] == '&')
{
evalarg_T nested_evalarg;
int orig_flags;
int evaluate;
if (evalarg == NULL)
{
CLEAR_FIELD(nested_evalarg);
--- 2104,2119 ----
*/
first = TRUE;
result = TRUE;
! p = eval_next_non_blank(*arg, evalarg, &getnext);
! while (p[0] == '&' && p[1] == '&')
{
evalarg_T nested_evalarg;
int orig_flags;
int evaluate;
+ if (getnext)
+ *arg = eval_next_line(evalarg);
+
if (evalarg == NULL)
{
CLEAR_FIELD(nested_evalarg);
***************
*** 2147,2152 ****
--- 2161,2168 ----
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = result;
}
+
+ p = eval_next_non_blank(*arg, evalarg, &getnext);
}
return OK;
*** ../vim-8.2.1062/src/testdir/test_vim9_expr.vim 2020-06-26
21:28:22.012863401 +0200
--- src/testdir/test_vim9_expr.vim 2020-06-26 21:34:53.039900980 +0200
***************
*** 117,122 ****
--- 117,142 ----
assert_equal([[], '', 0], g:vals)
enddef
+ def Test_expr2_vimscript()
+ " only checks line continuation
+ let lines =<< trim END
+ vim9script
+ let var = 0
+ || 1
+ assert_equal(1, var)
+ END
+ CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ let var = v:false
+ || v:true
+ || v:false
+ assert_equal(1, var)
+ END
+ CheckScriptSuccess(lines)
+ enddef
+
func Test_expr2_fails()
let msg = "white space required before and after '||'"
call CheckDefFailure(["let x = 1||2"], msg)
***************
*** 160,165 ****
--- 180,205 ----
assert_equal([[1], 'z', 0], g:vals)
enddef
+ def Test_expr3_vimscript()
+ " only checks line continuation
+ let lines =<< trim END
+ vim9script
+ let var = 0
+ && 1
+ assert_equal(0, var)
+ END
+ CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ let var = v:true
+ && v:true
+ && v:true
+ assert_equal(1, var)
+ END
+ CheckScriptSuccess(lines)
+ enddef
+
func Test_expr3_fails()
let msg = "white space required before and after '&&'"
call CheckDefFailure(["let x = 1&&2"], msg)
*** ../vim-8.2.1062/src/version.c 2020-06-26 21:28:22.012863401 +0200
--- src/version.c 2020-06-26 21:32:52.248170613 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1063,
/**/
--
"Software is like sex... it's better when it's free."
-- Linus Torvalds, initiator of the free Linux OS
Makes me wonder what FSF stands for...?
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ 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/202006261939.05QJdb3d2574790%40masaka.moolenaar.net.