changeset 21142:165cea61e974 v8.2.1122

patch 8.2.1122: Vim9: line continuation in dict member not recognized Commit: https://github.com/vim/vim/commit/442af2f89e29fb60790bffde2def9cd74a081780 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jul 3 21:09:52 2020 +0200 patch 8.2.1122: Vim9: line continuation in dict member not recognized Problem: Vim9: line continuation in dict member not recognized. Solution: Check for line continuation.
author Bram Moolenaar <Bram@vim.org>
date Fri, 03 Jul 2020 21:15:04 +0200
parents d745abd682f9
children f3dc82dda552
files src/eval.c src/testdir/test_vim9_expr.vim src/version.c
diffstat 3 files changed, 59 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -3362,7 +3362,7 @@ eval_index(
 	 *
 	 * Get the (first) variable from inside the [].
 	 */
-	*arg = skipwhite(*arg + 1);
+	*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
 	if (**arg == ':')
 	    empty1 = TRUE;
 	else if (eval1(arg, &var1, evalarg) == FAIL)	// recursive!
@@ -3377,10 +3377,11 @@ eval_index(
 	/*
 	 * Get the second variable from inside the [:].
 	 */
+	*arg = skipwhite_and_linebreak(*arg, evalarg);
 	if (**arg == ':')
 	{
 	    range = TRUE;
-	    *arg = skipwhite(*arg + 1);
+	    *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
 	    if (**arg == ']')
 		empty2 = TRUE;
 	    else if (eval1(arg, &var2, evalarg) == FAIL)	// recursive!
@@ -3400,6 +3401,7 @@ eval_index(
 	}
 
 	// Check for the ']'.
+	*arg = skipwhite_and_linebreak(*arg, evalarg);
 	if (**arg != ']')
 	{
 	    if (verbose)
@@ -5043,6 +5045,21 @@ handle_subscript(
 				      && (evalarg->eval_flags & EVAL_EVALUATE);
     int		ret = OK;
     dict_T	*selfdict = NULL;
+    int		check_white = TRUE;
+
+    // When at the end of the line and ".name" follows in the next line then
+    // consume the line break.  Only when rettv is a dict.
+    if (rettv->v_type == VAR_DICT)
+    {
+	int	getnext;
+	char_u	*p = eval_next_non_blank(*arg, evalarg, &getnext);
+
+	if (getnext && *p == '.' && ASCII_ISALPHA(p[1]))
+	{
+	    *arg = eval_next_line(evalarg);
+	    check_white = FALSE;
+	}
+    }
 
     // "." is ".name" lookup when we found a dict or when evaluating and
     // scriptversion is at least 2, where string concatenation is "..".
@@ -5054,7 +5071,7 @@ handle_subscript(
 			    && current_sctx.sc_version >= 2)))
 		    || (**arg == '(' && (!evaluate || rettv->v_type == VAR_FUNC
 					    || rettv->v_type == VAR_PARTIAL)))
-		&& !VIM_ISWHITE(*(*arg - 1)))
+		&& (!check_white || !VIM_ISWHITE(*(*arg - 1))))
 	    || (**arg == '-' && (*arg)[1] == '>')))
     {
 	if (**arg == '(')
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1138,6 +1138,43 @@ def Test_expr_member()
   call CheckDefExecFailure(["let d: dict<number>", "d = g:list_empty"], 'E1029: Expected dict but got list')
 enddef
 
+def Test_expr_member_vim9script()
+  let lines =<< trim END
+      vim9script
+      let d = #{one:
+      		'one',
+		two: 'two'}
+      assert_equal('one', d.one)
+      assert_equal('one', d
+                            .one)
+      assert_equal('one', d[
+			    'one'
+			    ])
+  END
+  CheckScriptSuccess(lines)
+
+  lines =<< trim END
+      vim9script
+      let l = [1,
+		  2,
+		  3, 4
+		  ]
+      assert_equal(2, l[
+			    1
+			    ])
+      assert_equal([2, 3], l[1 : 2])
+      assert_equal([1, 2, 3], l[
+				:
+				2
+				])
+      assert_equal([3, 4], l[
+				2
+				:
+				])
+  END
+  CheckScriptSuccess(lines)
+enddef
+
 def Test_expr7_option()
   " option
   set ts=11
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1122,
+/**/
     1121,
 /**/
     1120,