Problem: Vim9: cannot unlet an environment variable.
Solution: Implement unlet for $VAR.
g:somevar = "value"
unlet g:somevar
unlet! g:somevar
+ unlet $SOMEVAR
enddef
def Test_disassemble_unlet()
'unlet g:somevar.*' ..
'\d UNLET g:somevar.*' ..
'unlet! g:somevar.*' ..
- '\d UNLET! g:somevar.*',
+ '\d UNLET! g:somevar.*' ..
+ 'unlet $SOMEVAR.*' ..
+ '\d UNLETENV $SOMEVAR.*',
res)
enddef
' unlet s:svar',
'enddef',
], 'E1081:')
+
+ $ENVVAR = 'foobar'
+ assert_equal('foobar', $ENVVAR)
+ unlet $ENVVAR
+ assert_equal('', $ENVVAR)
enddef
func Test_wrong_type()
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 605,
/**/
604,
/**/
ISN_STORENR, // store number into local variable isn_arg.storenr.stnr_idx
ISN_UNLET, // unlet variable isn_arg.unlet.ul_name
+ ISN_UNLETENV, // unlet environment variable isn_arg.unlet.ul_name
// constants
ISN_PUSHNR, // push number isn_arg.number
* Generate an ISN_UNLET instruction.
*/
static int
-generate_UNLET(cctx_T *cctx, char_u *name, int forceit)
+generate_UNLET(cctx_T *cctx, isntype_T isn_type, char_u *name, int forceit)
{
isn_T *isn;
RETURN_OK_IF_SKIP(cctx);
- if ((isn = generate_instr(cctx, ISN_UNLET)) == NULL)
+ if ((isn = generate_instr(cctx, isn_type)) == NULL)
return FAIL;
isn->isn_arg.unlet.ul_name = vim_strsave(name);
isn->isn_arg.unlet.ul_forceit = forceit;
// Normal name. Only supports g:, w:, t: and b: namespaces.
*name_end = NUL;
- if (check_vim9_unlet(p) == FAIL)
+ if (*p == '$')
+ ret = generate_UNLET(cctx, ISN_UNLETENV, p + 1, eap->forceit);
+ else if (check_vim9_unlet(p) == FAIL)
ret = FAIL;
else
- ret = generate_UNLET(cctx, p, eap->forceit);
+ ret = generate_UNLET(cctx, ISN_UNLET, p, eap->forceit);
*name_end = cc;
return ret;
break;
case ISN_UNLET:
+ case ISN_UNLETENV:
vim_free(isn->isn_arg.unlet.ul_name);
break;
iptr->isn_arg.unlet.ul_forceit) == FAIL)
goto failed;
break;
+ case ISN_UNLETENV:
+ vim_unsetenv(iptr->isn_arg.unlet.ul_name);
+ break;
// create a list from items on the stack; uses a single allocation
// for the list header and the items
iptr->isn_arg.unlet.ul_forceit ? "!" : "",
iptr->isn_arg.unlet.ul_name);
break;
+ case ISN_UNLETENV:
+ smsg("%4d UNLETENV%s $%s", current,
+ iptr->isn_arg.unlet.ul_forceit ? "!" : "",
+ iptr->isn_arg.unlet.ul_name);
+ break;
case ISN_NEWLIST:
smsg("%4d NEWLIST size %lld", current,
(long long)(iptr->isn_arg.number));