int flags, // GLV_ values
class_T *cl_exec)
{
- int vim9script = in_vim9script();
int quiet = flags & GLV_QUIET;
char_u *key = NULL;
int len;
vartype_name(v_type));
#endif
- if (vim9script && lp->ll_valtype == NULL
+ if (current_script_is_vim9() && lp->ll_valtype == NULL
&& v != NULL
&& lp->ll_tv == &v->di_tv
&& ht != NULL && ht == get_script_local_ht())
if (lp->ll_valtype != NULL
&& check_typval_arg_type(lp->ll_valtype, rettv,
NULL, 0) == FAIL)
+ {
+ lp->ll_name_end = NULL;
return;
+ }
// If the lval is a List and the type of the list is not yet set,
// then set the item type from the declared type of the variable.
defcompile
END
v9.CheckScriptSuccess(lines)
+
+ # Modifying a variable type using the legacy command at script level
+ lines =<< trim END
+ vim9script
+ var l: list<number> = [1, 2]
+ legacy let s:l[0] = 'x'
+ END
+ v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got string', 3)
+
+ # try with dict type
+ lines =<< trim END
+ vim9script
+ var d: dict<number>
+ legacy let s:d['a'] = 'x'
+ END
+ v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got string', 3)
+
+ # Modifying a variable type using the legacy command in a def function
+ lines =<< trim END
+ vim9script
+ var l: list<number> = [1, 2]
+ def Fn()
+ legacy let s:l[0] = 'x'
+ enddef
+ Fn()
+ END
+ v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
+
+ # try with dict type
+ lines =<< trim END
+ vim9script
+ var d: dict<string>
+ def Fn()
+ legacy let s:d['a'] = 10
+ enddef
+ Fn()
+ END
+ v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected string but got number', 1)
+
+ # after the first error, the assignment should be aborted
+ lines =<< trim END
+ vim9script
+ var l: list<number> = [1, 2]
+ legacy let [s:l[0], s:l[1]] = ['x', 1.0]
+ END
+ v9.CheckSourceFailureList(lines, ['', 'E1012: Type mismatch; expected number but got string'], 3)
enddef
let g:dict_number = #{one: 1, two: 2}