CheckDefFailure(['const foo: number'], 'E1021:')
enddef
+def Test_script_local_in_legacy()
+ # OK to define script-local later when prefixed with s:
+ var lines =<< trim END
+ def SetLater()
+ s:legacy = 'two'
+ enddef
+ defcompile
+ let s:legacy = 'one'
+ call SetLater()
+ call assert_equal('two', s:legacy)
+ END
+ CheckScriptSuccess(lines)
+
+ # OK to leave out s: prefix when script-local already defined
+ lines =<< trim END
+ let s:legacy = 'one'
+ def SetNoPrefix()
+ legacy = 'two'
+ enddef
+ call SetNoPrefix()
+ call assert_equal('two', s:legacy)
+ END
+ CheckScriptSuccess(lines)
+
+ # Not OK to leave out s: prefix when script-local defined later
+ lines =<< trim END
+ def SetLaterNoPrefix()
+ legacy = 'two'
+ enddef
+ defcompile
+ let s:legacy = 'one'
+ END
+ CheckScriptFailure(lines, 'E476:', 1)
+enddef
+
def Test_var_type_check()
var lines =<< trim END
vim9script
return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
case dest_script:
if (scriptvar_idx < 0)
- {
- char_u *name_s = name;
- int r;
-
- // "s:" is included in the name.
- r = generate_OLDSCRIPT(cctx, ISN_STORES, name_s,
+ // "s:" may be included in the name.
+ return generate_OLDSCRIPT(cctx, ISN_STORES, name,
scriptvar_sid, type);
- if (name_s != name)
- vim_free(name_s);
- return r;
- }
return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT,
scriptvar_sid, scriptvar_idx, type);
case dest_local:
? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
FALSE, cctx)
: script_var_exists(var_start, lhs->lhs_varlen,
- TRUE, cctx)) == OK;
+ FALSE, cctx)) == OK;
imported_T *import =
find_imported(var_start, lhs->lhs_varlen, cctx);