Skip to content

Commit 5dd839c

Browse files
committed
patch 8.2.3202: Vim9: tests are only executed for legacy script
Problem: Vim9: tests are only executed for legacy script. Solution: Run more tests also for Vim9 script. Fix uncovered problems.
1 parent 2b59df0 commit 5dd839c

4 files changed

Lines changed: 127 additions & 39 deletions

File tree

src/ex_docmd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,8 @@ find_ex_command(
34513451
// "varname[]" is an expression.
34523452
*p == '['
34533453
// "varname.key" is an expression.
3454-
|| (*p == '.' && ASCII_ISALPHA(p[1]))))
3454+
|| (*p == '.' && (ASCII_ISALPHA(p[1])
3455+
|| p[1] == '_'))))
34553456
{
34563457
char_u *after = eap->cmd;
34573458

src/testdir/test_listdict.vim

Lines changed: 116 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,17 @@ func Test_list_unlet()
109109
unlet l[2:3]
110110
call assert_equal([0, 1], l)
111111

112-
let l = [0, 1, 2, 3]
113-
call assert_fails('unlet l[2:1]', 'E684:')
114-
let l = [0, 1, 2, 3]
115-
call assert_fails('unlet l[-1:2]', 'E684:')
112+
let lines =<< trim END
113+
VAR l = [0, 1, 2, 3]
114+
unlet l[2 : 1]
115+
END
116+
call CheckLegacyAndVim9Failure(lines, 'E684:')
117+
118+
let lines =<< trim END
119+
VAR l = [0, 1, 2, 3]
120+
unlet l[-1 : 2]
121+
END
122+
call CheckLegacyAndVim9Failure(lines, 'E684:')
116123
endfunc
117124

118125
" assignment to a list
@@ -126,9 +133,33 @@ func Test_list_assign()
126133
END
127134
call CheckLegacyAndVim9Success(lines)
128135

129-
let l = [0, 1, 2, 3]
130-
call assert_fails('let [va, vb] = l', 'E687:')
131-
call assert_fails('let [va, vb] = l[1:1]', 'E688:')
136+
let lines =<< trim END
137+
let l = [0, 1, 2, 3]
138+
let [va, vb] = l
139+
END
140+
call CheckScriptFailure(lines, 'E687:')
141+
let lines =<< trim END
142+
var l = [0, 1, 2, 3]
143+
var va = 0
144+
var vb = 0
145+
[va, vb] = l
146+
END
147+
call CheckScriptFailure(['vim9script'] + lines, 'E687:')
148+
call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 4')
149+
150+
let lines =<< trim END
151+
let l = [0, 1, 2, 3]
152+
let [va, vb] = l[1:1]
153+
END
154+
call CheckScriptFailure(lines, 'E688:')
155+
let lines =<< trim END
156+
var l = [0, 1, 2, 3]
157+
var va = 0
158+
var vb = 0
159+
[va, vb] = l[1 : 1]
160+
END
161+
call CheckScriptFailure(['vim9script'] + lines, 'E688:')
162+
call CheckDefExecFailure(lines, 'E1093: Expected 2 items but got 1')
132163
endfunc
133164

134165
" test for range assign
@@ -248,23 +279,29 @@ let s:dict_with_spaces_lit = #{one : 1 , two : 2 , three : 3}
248279

249280
" Dictionary identity
250281
func Test_dict_identity()
251-
let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},}
252-
let dd = d
253-
let dx = copy(d)
254-
call assert_true(d == dd)
255-
call assert_false(d isnot dd)
256-
call assert_true(d is dd)
257-
call assert_true(d == dx)
258-
call assert_false(d is dx)
259-
call assert_true(d isnot dx)
282+
let lines =<< trim END
283+
VAR d = {'1': 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1}, }
284+
VAR dd = d
285+
VAR dx = copy(d)
286+
call assert_true(d == dd)
287+
call assert_false(d isnot dd)
288+
call assert_true(d is dd)
289+
call assert_true(d == dx)
290+
call assert_false(d is dx)
291+
call assert_true(d isnot dx)
292+
END
293+
call CheckLegacyAndVim9Success(lines)
260294
endfunc
261295

262296
" removing items with :unlet
263297
func Test_dict_unlet()
264-
let d = {'b':'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
265-
unlet d.b
266-
unlet d[-1]
267-
call assert_equal({'1': 99, '3': 33}, d)
298+
let lines =<< trim END
299+
VAR d = {'b': 'bbb', '1': 99, '3': 33, '-1': {'a': 1}}
300+
unlet d.b
301+
unlet d[-1]
302+
call assert_equal({'1': 99, '3': 33}, d)
303+
END
304+
call CheckLegacyAndVim9Success(lines)
268305
endfunc
269306

270307
" manipulating a big Dictionary (hashtable.c has a border of 1000 entries)
@@ -332,8 +369,30 @@ func Test_dict_assign()
332369
let d._ = 2
333370
call assert_equal({'1': 1, '_': 2}, d)
334371

335-
let n = 0
336-
call assert_fails('let n.key = 3', 'E1203: Dot can only be used on a dictionary: n.key = 3')
372+
let lines =<< trim END
373+
VAR d = {}
374+
LET d.a = 1
375+
LET d._ = 2
376+
call assert_equal({'a': 1, '_': 2}, d)
377+
END
378+
call CheckLegacyAndVim9Success(lines)
379+
380+
let lines =<< trim END
381+
let n = 0
382+
let n.key = 3
383+
END
384+
call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
385+
let lines =<< trim END
386+
vim9script
387+
var n = 0
388+
n.key = 3
389+
END
390+
call CheckScriptFailure(lines, 'E1203: Dot can only be used on a dictionary: n.key = 3')
391+
let lines =<< trim END
392+
var n = 0
393+
n.key = 3
394+
END
395+
call CheckDefFailure(lines, 'E1141:')
337396
endfunc
338397

339398
" Function in script-local List or Dict
@@ -350,13 +409,41 @@ endfunc
350409

351410
" Test removing items in a dictionary
352411
func Test_dict_func_remove()
353-
let d = {1:'a', 2:'b', 3:'c'}
354-
call assert_equal('b', remove(d, 2))
355-
call assert_equal({1:'a', 3:'c'}, d)
412+
let lines =<< trim END
413+
VAR d = {1: 'a', 2: 'b', 3: 'c'}
414+
call assert_equal('b', remove(d, 2))
415+
call assert_equal({1: 'a', 3: 'c'}, d)
416+
END
417+
call CheckLegacyAndVim9Success(lines)
418+
419+
let lines =<< trim END
420+
VAR d = {1: 'a', 3: 'c'}
421+
call remove(d, 1, 2)
422+
END
423+
call CheckLegacyAndVim9Failure(lines, 'E118:')
356424

357-
call assert_fails("call remove(d, 1, 2)", 'E118:')
358-
call assert_fails("call remove(d, 'a')", 'E716:')
359-
call assert_fails("call remove(d, [])", 'E730:')
425+
let lines =<< trim END
426+
VAR d = {1: 'a', 3: 'c'}
427+
call remove(d, 'a')
428+
END
429+
call CheckLegacyAndVim9Failure(lines, 'E716:')
430+
431+
let lines =<< trim END
432+
let d = {1: 'a', 3: 'c'}
433+
call remove(d, [])
434+
END
435+
call CheckScriptFailure(lines, 'E730:')
436+
let lines =<< trim END
437+
vim9script
438+
var d = {1: 'a', 3: 'c'}
439+
call remove(d, [])
440+
END
441+
call CheckScriptFailure(lines, 'E1174: String required for argument 2')
442+
let lines =<< trim END
443+
var d = {1: 'a', 3: 'c'}
444+
call remove(d, [])
445+
END
446+
call CheckDefExecFailure(lines, 'E1013: Argument 2: type mismatch, expected string but got list<unknown>')
360447
endfunc
361448

362449
" Nasty: remove func from Dict that's being called (works)
@@ -372,7 +459,7 @@ endfunc
372459
func Test_dict_literal_keys()
373460
call assert_equal({'one': 1, 'two2': 2, '3three': 3, '44': 4}, #{one: 1, two2: 2, 3three: 3, 44: 4},)
374461

375-
" why *{} cannot be used
462+
" why *{} cannot be used for a literal dictionary
376463
let blue = 'blue'
377464
call assert_equal('6', trim(execute('echo 2 *{blue: 3}.blue')))
378465
endfunc
@@ -564,15 +651,13 @@ endfunc
564651

565652
" No :unlet after lock on dict:
566653
func Test_dict_lock_unlet()
567-
unlet! d
568654
let d = {'a': 99, 'b': 100}
569655
lockvar 1 d
570656
call assert_fails('unlet d.a', 'E741:')
571657
endfunc
572658

573659
" unlet after lock on dict item
574660
func Test_dict_item_lock_unlet()
575-
unlet! d
576661
let d = {'a': 99, 'b': 100}
577662
lockvar d.a
578663
unlet d.a
@@ -581,7 +666,6 @@ endfunc
581666

582667
" filter() after lock on dict item
583668
func Test_dict_lock_filter()
584-
unlet! d
585669
let d = {'a': 99, 'b': 100}
586670
lockvar d.a
587671
call filter(d, 'v:key != "a"')
@@ -590,7 +674,6 @@ endfunc
590674

591675
" map() after lock on dict
592676
func Test_dict_lock_map()
593-
unlet! d
594677
let d = {'a': 99, 'b': 100}
595678
lockvar 1 d
596679
call map(d, 'v:val + 200')
@@ -599,7 +682,6 @@ endfunc
599682

600683
" No extend() after lock on dict item
601684
func Test_dict_lock_extend()
602-
unlet! d
603685
let d = {'a': 99, 'b': 100}
604686
lockvar d.a
605687
call assert_fails("call extend(d, {'a' : 123})", 'E741:')
@@ -608,7 +690,6 @@ endfunc
608690

609691
" Cannot use += with a locked dict
610692
func Test_dict_lock_operator()
611-
unlet! d
612693
let d = {}
613694
lockvar d
614695
call assert_fails("let d += {'k' : 10}", 'E741:')
@@ -711,9 +792,6 @@ func Test_func_arg_list()
711792
call s:arg_list_test(1, 2, [3, 4], {5: 6})
712793
endfunc
713794

714-
func Test_dict_item_locked()
715-
endfunc
716-
717795
" Tests for reverse(), sort(), uniq()
718796
func Test_reverse_sort_uniq()
719797
let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5]

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3202,
758760
/**/
759761
3201,
760762
/**/

src/vim9execute.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,13 @@ exec_instructions(ectx_T *ectx)
27112711
else
27122712
n2 = list_idx_of_item(l, li2);
27132713
}
2714+
if (status != FAIL
2715+
&& tv_idx2->v_type != VAR_SPECIAL
2716+
&& n2 < n1)
2717+
{
2718+
semsg(_(e_listidx), n2);
2719+
status = FAIL;
2720+
}
27142721
if (status != FAIL
27152722
&& list_unlet_range(l, li, NULL, n1,
27162723
tv_idx2->v_type != VAR_SPECIAL, n2)

0 commit comments

Comments
 (0)