diff src/vim9compile.c @ 33250:575dd775b7fb v9.0.1897

patch 9.0.1897: Vim9: confusing error with .= in compiled functions Commit: https://github.com/vim/vim/commit/504543f98be2ddb6d49ea2f7e996112868fc54ed Author: Christian Brabandt <cb@256bit.org> Date: Mon Sep 11 20:08:50 2023 +0200 patch 9.0.1897: Vim9: confusing error with .= in compiled functions 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>
author Christian Brabandt <cb@256bit.org>
date Mon, 11 Sep 2023 20:15:06 +0200
parents 108d890d887f
children aba1fa2b7d1e
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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;
 		}
 	    }