diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 5043fad23f..c5f564ec75 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -3131,6 +3131,28 @@ def Test_type_specification_in_assignment() Foo() END v9.CheckSourceFailure(lines, "E476: Invalid command: MyVar: string = 'abc'", 1) + + # redeclare an existing def local variable with a type + lines =<< trim END + vim9script + def Foo() + var n: number = 10 + var n: number = 20 + enddef + Foo() + END + v9.CheckSourceFailure(lines, 'E1017: Variable already declared: n', 2) + + # redeclare an existing def local constant with a type + lines =<< trim END + vim9script + def Foo() + const x: number = 1 + const x: number = 2 + enddef + Foo() + END + v9.CheckSourceFailure(lines, 'E1017: Variable already declared: x', 2) enddef let g:someVar = 'X' diff --git a/src/version.c b/src/version.c index 55f8b8a7ec..de7154c646 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 543, /**/ 542, /**/ diff --git a/src/vim9compile.c b/src/vim9compile.c index ea56f4ec5b..cbee429763 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1949,7 +1949,8 @@ compile_lhs_var_dest( int cmdidx, char_u *var_start, char_u *var_end, - int is_decl) + int is_decl, + int has_cmd) // "var" before "var_start" { int declare_error = FALSE; @@ -2004,8 +2005,8 @@ compile_lhs_var_dest( char_u *p = skipwhite(lhs->lhs_end); if (p[0] == '.' && p[1] == '=') emsg(_(e_dot_equal_not_supported_with_script_version_two)); - else if (p[0] == ':') - // type specified in a non-var assignment + else if (p[0] == ':' && !has_cmd) + // type specified in an assignment without "var" semsg(_(e_trailing_characters_str), p); else semsg(_(e_variable_already_declared_str), lhs->lhs_name); @@ -2309,7 +2310,7 @@ compile_lhs( { // compile the LHS destination if (compile_lhs_var_dest(cctx, lhs, cmdidx, var_start, var_end, - is_decl) == FAIL) + is_decl, has_cmd) == FAIL) return FAIL; }