Skip to content

Commit 77b2097

Browse files
committed
patch 8.2.1710: Vim9: list of list type can be wrong
Problem: Vim9: list of list type can be wrong. Solution: Use VAR_UNKNOWN for empty list. Recognize VAR_UNKNOWN when looking for a common type. (closes #6979)
1 parent dec0751 commit 77b2097

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,10 @@ def Test_expr7_list()
15131513
2] [3,
15141514
4]
15151515

1516+
let llstring: list<list<string>> = [['text'], []]
1517+
llstring = [[], ['text']]
1518+
llstring = [[], []]
1519+
15161520
CheckDefFailure(["let x = 1234[3]"], 'E1107:', 1)
15171521
CheckDefExecFailure(["let x = g:anint[3]"], 'E1062:', 1)
15181522

@@ -1718,6 +1722,14 @@ def Test_expr7_dict()
17181722
mixed = #{a: 234}
17191723
mixed = #{}
17201724

1725+
let dictlist: dict<list<string>> = #{absent: [], present: ['hi']}
1726+
dictlist = #{absent: ['hi'], present: []}
1727+
dictlist = #{absent: [], present: []}
1728+
1729+
let dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}}
1730+
dictdict = #{one: #{}, two: #{a: 'text'}}
1731+
dictdict = #{one: #{}, two: #{}}
1732+
17211733
CheckDefFailure(["let x = #{a:8}"], 'E1069:', 1)
17221734
CheckDefFailure(["let x = #{a : 8}"], 'E1068:', 1)
17231735
CheckDefFailure(["let x = #{a :8}"], 'E1068:', 1)

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+
1710,
753755
/**/
754756
1709,
755757
/**/

src/vim9type.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,19 @@ common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap)
869869
return;
870870
}
871871

872+
// If either is VAR_UNKNOWN use the other type. An empty list/dict has no
873+
// specific type.
874+
if (type1->tt_type == VAR_UNKNOWN)
875+
{
876+
*dest = type2;
877+
return;
878+
}
879+
if (type2->tt_type == VAR_UNKNOWN)
880+
{
881+
*dest = type1;
882+
return;
883+
}
884+
872885
if (type1->tt_type == type2->tt_type)
873886
{
874887
if (type1->tt_type == VAR_LIST || type2->tt_type == VAR_DICT)
@@ -932,7 +945,7 @@ get_member_type_from_stack(
932945

933946
// Use "any" for an empty list or dict.
934947
if (count == 0)
935-
return &t_void;
948+
return &t_unknown;
936949

937950
// Use the first value type for the list member type, then find the common
938951
// type from following items.

0 commit comments

Comments
 (0)