]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.2200: Vim9: lambda without white space around -> is confusing v8.2.2200
authorBram Moolenaar <Bram@vim.org>
Wed, 23 Dec 2020 19:27:31 +0000 (20:27 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 23 Dec 2020 19:27:31 +0000 (20:27 +0100)
Problem:    Vim9: lambda without white space around -> is confusing.
Solution:   Require white space in a :def funtion. (issue #7503)

src/testdir/test_vim9_disassemble.vim
src/testdir/test_vim9_expr.vim
src/version.c
src/vim9compile.c

index 7f88cfa0d30934ee0523fd57191955ac616dd26b..c5b546a197b4b6bc962a101334bf627849744fb5 100644 (file)
@@ -1541,10 +1541,10 @@ def Test_disassemble_compare()
         ['{a: 1} is aDict', 'COMPAREDICT is'],
         ['{a: 1} isnot aDict', 'COMPAREDICT isnot'],
 
-        ['{->33} == {->44}', 'COMPAREFUNC =='],
-        ['{->33} != {->44}', 'COMPAREFUNC !='],
-        ['{->33} is {->44}', 'COMPAREFUNC is'],
-        ['{->33} isnot {->44}', 'COMPAREFUNC isnot'],
+        ['{-> 33} == {-> 44}', 'COMPAREFUNC =='],
+        ['{-> 33} != {-> 44}', 'COMPAREFUNC !='],
+        ['{-> 33} is {-> 44}', 'COMPAREFUNC is'],
+        ['{-> 33} isnot {-> 44}', 'COMPAREFUNC isnot'],
 
         ['77 == g:xx', 'COMPAREANY =='],
         ['77 != g:xx', 'COMPAREANY !='],
index f2c9200eea68897013d0cebd85cfa1c251a487cf..31c8827801fd2fae233774902421b57eadb1f29b 100644 (file)
@@ -1863,6 +1863,10 @@ def Test_expr7_lambda()
   END
   CheckDefAndScriptSuccess(lines)
 
+  CheckDefFailure(["var Ref = {a->a + 1}"], 'E720:')
+  CheckDefFailure(["var Ref = {a-> a + 1}"], 'E720:')
+  CheckDefFailure(["var Ref = {a ->a + 1}"], 'E720:')
+
   CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:', 1)
   # error is in first line of the lambda
   CheckDefFailure(["var L = {a -> a + b}"], 'E1001:', 0)
@@ -2538,7 +2542,7 @@ func Test_expr7_fails()
   call CheckDefFailure(["'yes'->", "Echo()"], 'E488: Trailing characters: ->', 1)
 
   call CheckDefExecFailure(["[1, 2->len()"], 'E697:', 2)
-  call CheckDefExecFailure(["{a: 1->len()"], 'E451:', 1)
+  call CheckDefExecFailure(["{a: 1->len()"], 'E723:', 2)
   call CheckDefExecFailure(["{['a']: 1->len()"], 'E723:', 2)
 endfunc
 
index 0fadf6b930b5eb7822ab4bb2b06506633c968179..e3fd6c1fe778028c762346d52704cde7bc864799 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2200,
 /**/
     2199,
 /**/
index b3d591d2366e230228aca254c3d1f44c6aa0a69f..7d653a7bd65f7c24bb14ffd233fd2dd91cb0b473 100644 (file)
@@ -3915,14 +3915,19 @@ compile_expr7(
         * Dictionary: {'key': val, 'key': val}
         */
        case '{':   {
-                       char_u *start = skipwhite(*arg + 1);
-                       garray_T ga_arg;
+                       char_u      *start = skipwhite(*arg + 1);
+                       char_u      *after = start;
+                       garray_T    ga_arg;
 
                        // Find out what comes after the arguments.
-                       ret = get_function_args(&start, '-', NULL,
+                       ret = get_function_args(&after, '-', NULL,
                                        &ga_arg, TRUE, NULL, NULL,
                                                             TRUE, NULL, NULL);
-                       if (ret != FAIL && *start == '>')
+                       if (ret != FAIL && after[0] == '>'
+                               && ((after > start + 2
+                                                    && VIM_ISWHITE(after[-2]))
+                               || after == start + 1)
+                               && IS_WHITE_OR_NUL(after[1]))
                            ret = compile_lambda(arg, cctx);
                        else
                            ret = compile_dict(arg, cctx, ppconst);