1
0
forked from aniani/vim

patch 8.2.0285: unused error message; cannot create s:var

Problem:    Unused error message. Cannot create s:var.
Solution:   Remove the error message. Make assignment to s:var work.
This commit is contained in:
Bram Moolenaar
2020-02-19 22:31:48 +01:00
parent c0d656c89d
commit 0bbf722aaa
4 changed files with 37 additions and 31 deletions

View File

@@ -65,6 +65,8 @@ def Test_assignment()
assert_equal('xxxyyy', s:appendToMe) assert_equal('xxxyyy', s:appendToMe)
s:addToMe += 222 s:addToMe += 222
assert_equal(333, s:addToMe) assert_equal(333, s:addToMe)
s:newVar = 'new'
assert_equal('new', s:newVar)
enddef enddef
func Test_assignment_failure() func Test_assignment_failure()

View File

@@ -738,6 +738,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
285,
/**/ /**/
284, 284,
/**/ /**/

View File

@@ -3284,10 +3284,9 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
} }
} }
} }
else if ((STRNCMP(arg, "s:", 2) == 0 else if (STRNCMP(arg, "s:", 2) == 0
? lookup_script(arg + 2, varlen - 2) || lookup_script(arg, varlen) == OK
: lookup_script(arg, varlen)) == OK || find_imported(arg, varlen, cctx) != NULL)
|| find_imported(arg, varlen, cctx) != NULL)
{ {
dest = dest_script; dest = dest_script;
if (is_decl) if (is_decl)
@@ -3566,7 +3565,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
idx = get_script_item_idx(sid, rawname, TRUE); idx = get_script_item_idx(sid, rawname, TRUE);
// TODO: specific type // TODO: specific type
if (idx < 0) if (idx < 0)
generate_OLDSCRIPT(cctx, ISN_STORES, rawname, sid, &t_any); generate_OLDSCRIPT(cctx, ISN_STORES, name, sid, &t_any);
else else
generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT, generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT,
sid, idx, &t_any); sid, idx, &t_any);

View File

@@ -355,6 +355,20 @@ call_partial(typval_T *tv, int argcount, ectx_T *ectx)
return OK; return OK;
} }
/*
* Store "tv" in variable "name".
* This is for s: and g: variables.
*/
static void
store_var(char_u *name, typval_T *tv)
{
funccal_entry_T entry;
save_funccal(&entry);
set_var_const(name, NULL, tv, FALSE, 0);
restore_funccal();
}
/* /*
* Execute a function by "name". * Execute a function by "name".
* This can be a builtin function, user function or a funcref. * This can be a builtin function, user function or a funcref.
@@ -556,6 +570,7 @@ call_def_function(
iptr->isn_arg.loadstore.ls_sid); iptr->isn_arg.loadstore.ls_sid);
char_u *name = iptr->isn_arg.loadstore.ls_name; char_u *name = iptr->isn_arg.loadstore.ls_name;
dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE); dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE);
if (di == NULL) if (di == NULL)
{ {
semsg(_(e_undefvar), name); semsg(_(e_undefvar), name);
@@ -574,10 +589,9 @@ call_def_function(
// load g: variable // load g: variable
case ISN_LOADG: case ISN_LOADG:
{ {
dictitem_T *di; dictitem_T *di = find_var_in_ht(get_globvar_ht(), 0,
di = find_var_in_ht(get_globvar_ht(), 0,
iptr->isn_arg.string, TRUE); iptr->isn_arg.string, TRUE);
if (di == NULL) if (di == NULL)
{ {
semsg(_("E121: Undefined variable: g:%s"), semsg(_("E121: Undefined variable: g:%s"),
@@ -617,12 +631,8 @@ call_def_function(
if (ga_grow(&ectx.ec_stack, 1) == FAIL) if (ga_grow(&ectx.ec_stack, 1) == FAIL)
goto failed; goto failed;
if (get_env_tv(&name, &optval, TRUE) == FAIL) // name is always valid, checked when compiling
{ (void)get_env_tv(&name, &optval, TRUE);
semsg(_("E1060: Invalid environment variable name: %s"),
iptr->isn_arg.string);
goto failed;
}
*STACK_TV_BOT(0) = optval; *STACK_TV_BOT(0) = optval;
++ectx.ec_stack.ga_len; ++ectx.ec_stack.ga_len;
} }
@@ -653,16 +663,16 @@ call_def_function(
hashtab_T *ht = &SCRIPT_VARS( hashtab_T *ht = &SCRIPT_VARS(
iptr->isn_arg.loadstore.ls_sid); iptr->isn_arg.loadstore.ls_sid);
char_u *name = iptr->isn_arg.loadstore.ls_name; char_u *name = iptr->isn_arg.loadstore.ls_name;
dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE); dictitem_T *di = find_var_in_ht(ht, 0, name + 2, TRUE);
if (di == NULL)
{
semsg(_(e_undefvar), name);
goto failed;
}
--ectx.ec_stack.ga_len; --ectx.ec_stack.ga_len;
clear_tv(&di->di_tv); if (di == NULL)
di->di_tv = *STACK_TV_BOT(0); store_var(iptr->isn_arg.string, STACK_TV_BOT(0));
else
{
clear_tv(&di->di_tv);
di->di_tv = *STACK_TV_BOT(0);
}
} }
break; break;
@@ -750,14 +760,7 @@ call_def_function(
di = find_var_in_ht(get_globvar_ht(), 0, di = find_var_in_ht(get_globvar_ht(), 0,
iptr->isn_arg.string + 2, TRUE); iptr->isn_arg.string + 2, TRUE);
if (di == NULL) if (di == NULL)
{ store_var(iptr->isn_arg.string, STACK_TV_BOT(0));
funccal_entry_T entry;
save_funccal(&entry);
set_var_const(iptr->isn_arg.string, NULL,
STACK_TV_BOT(0), FALSE, 0);
restore_funccal();
}
else else
{ {
clear_tv(&di->di_tv); clear_tv(&di->di_tv);
@@ -1723,7 +1726,7 @@ ex_disassemble(exarg_T *eap)
scriptitem_T *si = SCRIPT_ITEM( scriptitem_T *si = SCRIPT_ITEM(
iptr->isn_arg.loadstore.ls_sid); iptr->isn_arg.loadstore.ls_sid);
smsg("%4d STORES s:%s in %s", current, smsg("%4d STORES %s in %s", current,
iptr->isn_arg.string, si->sn_name); iptr->isn_arg.string, si->sn_name);
} }
break; break;