Skip to content

Commit 504543f

Browse files
committed
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 <[email protected]>
1 parent 6b9c202 commit 504543f

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

src/testdir/test_vim9_cmd.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ def Test_vim9cmd()
7979
legacy echo version
8080
END
8181
v9.CheckScriptSuccess(lines)
82+
83+
lines =<< trim END
84+
vim9script
85+
def Func()
86+
var d: dict<string>
87+
d.k .= ''
88+
enddef
89+
defcompile
90+
END
91+
v9.CheckScriptFailure(lines, 'E985:')
92+
lines =<< trim END
93+
vim9script
94+
def Func()
95+
var d: dict<string>
96+
d.k ,= ''
97+
enddef
98+
defcompile
99+
END
100+
v9.CheckScriptFailure(lines, 'E1017:')
82101
enddef
83102

84103
def Test_defcompile_fails()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ static char *(features[]) =
699699

700700
static int included_patches[] =
701701
{ /* Add new patch number below this line */
702+
/**/
703+
1897,
702704
/**/
703705
1896,
704706
/**/

src/vim9compile.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,14 @@ compile_lhs(
16691669
{
16701670
if (is_decl)
16711671
{
1672-
semsg(_(e_variable_already_declared_str), lhs->lhs_name);
1672+
// if we come here with what looks like an assignment like .=
1673+
// but which has been reject by assignment_len() from may_compile_assignment
1674+
// give a better error message
1675+
char_u *p = skipwhite(lhs->lhs_end);
1676+
if (p[0] == '.' && p[1] == '=')
1677+
emsg(_(e_dot_equal_not_supported_with_script_version_two));
1678+
else
1679+
semsg(_(e_variable_already_declared_str), lhs->lhs_name);
16731680
return FAIL;
16741681
}
16751682
}

0 commit comments

Comments
 (0)