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'
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;
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);
{
// 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;
}