]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1897: Vim9: confusing error with .= in compiled functions v9.0.1897
authorChristian Brabandt <cb@256bit.org>
Mon, 11 Sep 2023 18:08:50 +0000 (20:08 +0200)
committerChristian Brabandt <cb@256bit.org>
Mon, 11 Sep 2023 18:08:50 +0000 (20:08 +0200)
Problem:  Vim9: confusing error with .= in compiled functions
Solution: Check in error condition, if .= was attempted and in that case
          give a different error message.

closes: #12972
closes: #13066

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9compile.c

index 0fe6e7ca0183085044b6eac5151503c92e59ab95..a9e10e797c3186d004192982ab222fc7c7a8189d 100644 (file)
@@ -79,6 +79,25 @@ def Test_vim9cmd()
       legacy echo version
   END
   v9.CheckScriptSuccess(lines)
+
+  lines =<< trim END
+    vim9script
+    def Func()
+        var d: dict<string>
+        d.k .= ''
+    enddef
+    defcompile
+  END
+  v9.CheckScriptFailure(lines, 'E985:')
+  lines =<< trim END
+    vim9script
+    def Func()
+        var d: dict<string>
+        d.k ,= ''
+    enddef
+    defcompile
+  END
+  v9.CheckScriptFailure(lines, 'E1017:')
 enddef
 
 def Test_defcompile_fails()
index 937f8b8ab9d75b0f6cecebb021f972bacf56c299..aaa50da4b37a9bf6ce1f0177aaa4927b0c126616 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1897,
 /**/
     1896,
 /**/
index 7d24f21c8d3387d5181028a3f97c7dc30133f206..cc4aa46386a7c30e5e94ce0bb2d9bc93cc0da8e6 100644 (file)
@@ -1669,7 +1669,14 @@ compile_lhs(
            {
                if (is_decl)
                {
-                   semsg(_(e_variable_already_declared_str), lhs->lhs_name);
+                   // if we come here with what looks like an assignment like .=
+                   // but which has been reject by assignment_len() from may_compile_assignment
+                   // give a better error message
+                   char_u *p = skipwhite(lhs->lhs_end);
+                   if (p[0] == '.' && p[1] == '=')
+                       emsg(_(e_dot_equal_not_supported_with_script_version_two));
+                   else
+                       semsg(_(e_variable_already_declared_str), lhs->lhs_name);
                    return FAIL;
                }
            }