Mercurial > vim
comparison src/testdir/test_vim9_expr.vim @ 21715:571832713efa v8.2.1407
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Commit: https://github.com/vim/vim/commit/127542bcebeb6480493b09d75a3be1d98a5f7797
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 9 17:22:04 2020 +0200
patch 8.2.1407: Vim9: type of list and dict only depends on first item
Problem: Vim9: type of list and dict only depends on first item.
Solution: Use all items to decide about the type.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 Aug 2020 17:30:03 +0200 |
parents | f41c646cb8b9 |
children | ef3b31d510d2 |
comparison
equal
deleted
inserted
replaced
21714:e5d6e27da443 | 21715:571832713efa |
---|---|
1332 | 1332 |
1333 def Test_expr7_list() | 1333 def Test_expr7_list() |
1334 # list | 1334 # list |
1335 assert_equal(g:list_empty, []) | 1335 assert_equal(g:list_empty, []) |
1336 assert_equal(g:list_empty, [ ]) | 1336 assert_equal(g:list_empty, [ ]) |
1337 assert_equal(g:list_mixed, [1, 'b', false,]) | 1337 |
1338 let numbers: list<number> = [1, 2, 3] | |
1339 numbers = [1] | |
1340 numbers = [] | |
1341 | |
1342 let strings: list<string> = ['a', 'b', 'c'] | |
1343 strings = ['x'] | |
1344 strings = [] | |
1345 | |
1346 let mixed: list<any> = [1, 'b', false,] | |
1347 assert_equal(g:list_mixed, mixed) | |
1338 assert_equal('b', g:list_mixed[1]) | 1348 assert_equal('b', g:list_mixed[1]) |
1339 | 1349 |
1340 echo [1, | 1350 echo [1, |
1341 2] [3, | 1351 2] [3, |
1342 4] | 1352 4] |
1346 call CheckDefFailure(["let x = [1,2,3]"], 'E1069:') | 1356 call CheckDefFailure(["let x = [1,2,3]"], 'E1069:') |
1347 call CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E1029:') | 1357 call CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E1029:') |
1348 call CheckDefFailure(["let x = g:list_mixed["], 'E1097:') | 1358 call CheckDefFailure(["let x = g:list_mixed["], 'E1097:') |
1349 call CheckDefFailure(["let x = g:list_mixed[0"], 'E1097:') | 1359 call CheckDefFailure(["let x = g:list_mixed[0"], 'E1097:') |
1350 call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:') | 1360 call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:') |
1361 call CheckDefFailure(["let l: list<number> = [234, 'x']"], 'E1013:') | |
1362 call CheckDefFailure(["let l: list<number> = ['x', 234]"], 'E1013:') | |
1363 call CheckDefFailure(["let l: list<string> = [234, 'x']"], 'E1013:') | |
1364 call CheckDefFailure(["let l: list<string> = ['x', 123]"], 'E1013:') | |
1351 enddef | 1365 enddef |
1352 | 1366 |
1353 def Test_expr7_list_vim9script() | 1367 def Test_expr7_list_vim9script() |
1354 let lines =<< trim END | 1368 let lines =<< trim END |
1355 vim9script | 1369 vim9script |
1434 assert_equal(g:dict_empty, { }) | 1448 assert_equal(g:dict_empty, { }) |
1435 assert_equal(g:dict_one, {'one': 1}) | 1449 assert_equal(g:dict_one, {'one': 1}) |
1436 let key = 'one' | 1450 let key = 'one' |
1437 let val = 1 | 1451 let val = 1 |
1438 assert_equal(g:dict_one, {key: val}) | 1452 assert_equal(g:dict_one, {key: val}) |
1453 | |
1454 let numbers: dict<number> = #{a: 1, b: 2, c: 3} | |
1455 numbers = #{a: 1} | |
1456 numbers = #{} | |
1457 | |
1458 let strings: dict<string> = #{a: 'a', b: 'b', c: 'c'} | |
1459 strings = #{a: 'x'} | |
1460 strings = #{} | |
1461 | |
1462 let mixed: dict<any> = #{a: 'a', b: 42} | |
1463 mixed = #{a: 'x'} | |
1464 mixed = #{a: 234} | |
1465 mixed = #{} | |
1439 | 1466 |
1440 call CheckDefFailure(["let x = #{8: 8}"], 'E1014:') | 1467 call CheckDefFailure(["let x = #{8: 8}"], 'E1014:') |
1441 call CheckDefFailure(["let x = #{xxx}"], 'E720:') | 1468 call CheckDefFailure(["let x = #{xxx}"], 'E720:') |
1442 call CheckDefFailure(["let x = #{xxx: 1", "let y = 2"], 'E722:') | 1469 call CheckDefFailure(["let x = #{xxx: 1", "let y = 2"], 'E722:') |
1443 call CheckDefFailure(["let x = #{xxx: 1,"], 'E723:') | 1470 call CheckDefFailure(["let x = #{xxx: 1,"], 'E723:') |
1447 call CheckDefFailure(["let x = #"], 'E1015:') | 1474 call CheckDefFailure(["let x = #"], 'E1015:') |
1448 call CheckDefFailure(["let x += 1"], 'E1020:') | 1475 call CheckDefFailure(["let x += 1"], 'E1020:') |
1449 call CheckDefFailure(["let x = x + 1"], 'E1001:') | 1476 call CheckDefFailure(["let x = x + 1"], 'E1001:') |
1450 call CheckDefExecFailure(["let x = g:anint.member"], 'E715:') | 1477 call CheckDefExecFailure(["let x = g:anint.member"], 'E715:') |
1451 call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:') | 1478 call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:') |
1479 | |
1480 call CheckDefFailure(['let x: dict<number> = #{a: 234, b: "1"}'], 'E1013:') | |
1481 call CheckDefFailure(['let x: dict<number> = #{a: "x", b: 134}'], 'E1013:') | |
1482 call CheckDefFailure(['let x: dict<string> = #{a: 234, b: "1"}'], 'E1013:') | |
1483 call CheckDefFailure(['let x: dict<string> = #{a: "x", b: 134}'], 'E1013:') | |
1452 enddef | 1484 enddef |
1453 | 1485 |
1454 def Test_expr7_dict_vim9script() | 1486 def Test_expr7_dict_vim9script() |
1455 let lines =<< trim END | 1487 let lines =<< trim END |
1456 vim9script | 1488 vim9script |