Skip to content

Commit 0acbf5a

Browse files
committed
patch 8.2.2304: Vim9: no test for unletting an imported variable
Problem: Vim9: no test for unletting an imported variable. Solution: Add a test. Fix line number in error.
1 parent ecac591 commit 0acbf5a

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

src/testdir/test_vim9_assign.vim

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,11 @@ def Test_unlet()
13491349
assert_false(exists('s:somevar'))
13501350
unlet! s:somevar
13511351

1352+
CheckDefExecFailure([
1353+
'var dd = 111',
1354+
'unlet dd',
1355+
], 'E1081:', 2)
1356+
13521357
# dict unlet
13531358
var dd = {a: 1, b: 2, c: 3}
13541359
unlet dd['a']
@@ -1367,21 +1372,29 @@ def Test_unlet()
13671372
assert_equal([{a: 1}, {c: 3}], dl)
13681373

13691374
CheckDefExecFailure([
1370-
'var ll = test_null_list()',
1371-
'unlet ll[0]',
1372-
], 'E684:')
1375+
'var ll = test_null_list()',
1376+
'unlet ll[0]',
1377+
], 'E684:', 2)
1378+
CheckDefExecFailure([
1379+
'var ll = [1]',
1380+
'unlet ll[2]',
1381+
], 'E684:', 2)
13731382
CheckDefExecFailure([
1374-
'var ll = [1]',
1375-
'unlet ll[2]',
1376-
], 'E684:')
1383+
'var ll = [1]',
1384+
'unlet ll[g:astring]',
1385+
], 'E39:', 2)
13771386
CheckDefExecFailure([
1378-
'var dd = test_null_dict()',
1379-
'unlet dd["a"]',
1380-
], 'E716:')
1387+
'var dd = test_null_dict()',
1388+
'unlet dd["a"]',
1389+
], 'E716:', 2)
13811390
CheckDefExecFailure([
1382-
'var dd = {a: 1}',
1383-
'unlet dd["b"]',
1384-
], 'E716:')
1391+
'var dd = {a: 1}',
1392+
'unlet dd["b"]',
1393+
], 'E716:', 2)
1394+
CheckDefExecFailure([
1395+
'var dd = {a: 1}',
1396+
'unlet dd[g:alist]',
1397+
], 'E1105:', 2)
13851398

13861399
# can compile unlet before variable exists
13871400
g:someDict = {key: 'val'}
@@ -1426,6 +1439,18 @@ def Test_unlet()
14261439
'defcompile',
14271440
], 'E1081:')
14281441

1442+
writefile(['vim9script', 'export var svar = 1234'], 'XunletExport.vim')
1443+
var lines =<< trim END
1444+
vim9script
1445+
import svar from './XunletExport.vim'
1446+
def UnletSvar()
1447+
unlet svar
1448+
enddef
1449+
defcompile
1450+
END
1451+
CheckScriptFailure(lines, 'E1081:', 1)
1452+
delete('XunletExport.vim')
1453+
14291454
$ENVVAR = 'foobar'
14301455
assert_equal('foobar', $ENVVAR)
14311456
unlet $ENVVAR

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2304,
753755
/**/
754756
2303,
755757
/**/

src/vim9execute.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,7 @@ call_def_function(
19171917
// unlet a dict item, index must be a string
19181918
if (tv_idx->v_type != VAR_STRING)
19191919
{
1920+
SOURCING_LNUM = iptr->isn_lnum;
19201921
semsg(_(e_expected_str_but_got_str),
19211922
vartype_name(VAR_STRING),
19221923
vartype_name(tv_idx->v_type));
@@ -1935,6 +1936,7 @@ call_def_function(
19351936
if (di == NULL)
19361937
{
19371938
// NULL dict is equivalent to empty dict
1939+
SOURCING_LNUM = iptr->isn_lnum;
19381940
semsg(_(e_dictkey), key);
19391941
status = FAIL;
19401942
}
@@ -1950,6 +1952,7 @@ call_def_function(
19501952
// unlet a List item, index must be a number
19511953
if (tv_idx->v_type != VAR_NUMBER)
19521954
{
1955+
SOURCING_LNUM = iptr->isn_lnum;
19531956
semsg(_(e_expected_str_but_got_str),
19541957
vartype_name(VAR_NUMBER),
19551958
vartype_name(tv_idx->v_type));
@@ -1964,6 +1967,7 @@ call_def_function(
19641967
li = list_find(l, n);
19651968
if (li == NULL)
19661969
{
1970+
SOURCING_LNUM = iptr->isn_lnum;
19671971
semsg(_(e_listidx), n);
19681972
status = FAIL;
19691973
}
@@ -3129,6 +3133,7 @@ call_def_function(
31293133

31303134
case ISN_2STRING:
31313135
case ISN_2STRING_ANY:
3136+
SOURCING_LNUM = iptr->isn_lnum;
31323137
if (do_2string(STACK_TV_BOT(iptr->isn_arg.number),
31333138
iptr->isn_type == ISN_2STRING_ANY) == FAIL)
31343139
goto on_error;

0 commit comments

Comments
 (0)