Skip to content

Commit 6709816

Browse files
yegappanchrisbra
authored andcommitted
patch 9.0.2091: Vim9: cannot convert list to string using +=
Problem: Vim9: cannot convert list to string using += (after 9.0.2072) Solution: convert dict index to string later in compile_member() fixes: #13485 closes: #13486 Signed-off-by: Yegappan Lakshmanan <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 4f174f0 commit 6709816

4 files changed

Lines changed: 60 additions & 14 deletions

File tree

src/testdir/test_vim9_assign.vim

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2992,15 +2992,69 @@ def Test_list_item_assign()
29922992
vim9script
29932993

29942994
def Foo()
2995-
var l: list<list<string>> = [['x', 'x', 'x'], ['y', 'y', 'y']]
2996-
var z: number = 1
2995+
var l: list<list<string>> = [['x', 'x', 'x'], ['y', 'y', 'y']]
2996+
var z: number = 1
29972997

2998-
[l[1][2], z] = ['a', 20]
2999-
assert_equal([['x', 'x', 'x'], ['y', 'y', 'a']], l)
2998+
[l[1][2], z] = ['a', 20]
2999+
assert_equal([['x', 'x', 'x'], ['y', 'y', 'a']], l)
30003000
enddef
30013001
Foo()
30023002
END
30033003
v9.CheckSourceSuccess(lines)
3004+
3005+
lines =<< trim END
3006+
vim9script
3007+
3008+
var l: list<list<string>> = [['x', 'x', 'x'], ['y', 'y', 'y']]
3009+
var z: number = 1
3010+
3011+
[l[1][2], z] = ['a', 20]
3012+
assert_equal([['x', 'x', 'x'], ['y', 'y', 'a']], l)
3013+
END
3014+
v9.CheckSourceSuccess(lines)
3015+
enddef
3016+
3017+
" Test for assigning to a multi-dimensional dict item.
3018+
def Test_dict_item_assign()
3019+
# This used to fail with the error "E1105: Cannot convert list to string"
3020+
# (Github issue #13485)
3021+
var lines =<< trim END
3022+
vim9script
3023+
def F()
3024+
var d: dict<dict<number>> = {a: {b: 0}}
3025+
3026+
for group in keys(d)
3027+
d['a']['b'] += 1
3028+
endfor
3029+
assert_equal({a: {b: 1}}, d)
3030+
enddef
3031+
F()
3032+
END
3033+
v9.CheckSourceSuccess(lines)
3034+
3035+
# This used to crash Vim
3036+
lines =<< trim END
3037+
vim9script
3038+
def F()
3039+
var d: dict<dict<number>> = {a: {b: 0}}
3040+
d['a']['b'] += 1
3041+
assert_equal({a: {b: 1}}, d)
3042+
enddef
3043+
F()
3044+
END
3045+
v9.CheckSourceSuccess(lines)
3046+
3047+
# Assignment at script level
3048+
lines =<< trim END
3049+
vim9script
3050+
var d: dict<dict<number>> = {a: {b: 0}}
3051+
3052+
for group in keys(d)
3053+
d['a']['b'] += 1
3054+
endfor
3055+
assert_equal({a: {b: 1}}, d)
3056+
END
3057+
v9.CheckSourceSuccess(lines)
30043058
enddef
30053059

30063060
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/testdir/test_vim9_disassemble.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ def Test_disassemble_store_index()
560560
'\d LOAD $0\_s*' ..
561561
'\d MEMBER dd\_s*' ..
562562
'\d\+ USEDICT\_s*' ..
563-
'\d\+ 2STRING stack\[-2\]\_s*' ..
564563
'\d\+ STOREINDEX any\_s*' ..
565564
'\d\+ RETURN void',
566565
res)

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
2091,
707709
/**/
708710
2090,
709711
/**/

src/vim9compile.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,15 +2221,6 @@ compile_load_lhs(
22212221
return FAIL;
22222222
}
22232223

2224-
if (lhs->lhs_type->tt_type == VAR_DICT && var_start[varlen] == '[')
2225-
{
2226-
// If the lhs is a Dict variable and an item is accessed by "[",
2227-
// then need to convert the key into a string. The top item in the
2228-
// type stack is the Dict and the second last item is the key.
2229-
if (may_generate_2STRING(-2, FALSE, cctx) == FAIL)
2230-
return FAIL;
2231-
}
2232-
22332224
// Now we can properly check the type. The variable is indexed, thus
22342225
// we need the member type. For a class or object we don't know the
22352226
// type yet, it depends on what member is used.

0 commit comments

Comments
 (0)