]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.2091: Vim9: cannot convert list to string using += v9.0.2091
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 5 Nov 2023 09:07:03 +0000 (10:07 +0100)
committerChristian Brabandt <cb@256bit.org>
Sun, 5 Nov 2023 09:07:03 +0000 (10:07 +0100)
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 <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_assign.vim
src/testdir/test_vim9_disassemble.vim
src/version.c
src/vim9compile.c

index 91d302c4c5941486a0e490ec94d5f2d45c0347cd..3b4c78be07fd5f0e30807aa6fe598e0f951f942f 100644 (file)
@@ -2992,15 +2992,69 @@ def Test_list_item_assign()
     vim9script
 
     def Foo()
-        var l: list<list<string>> = [['x', 'x', 'x'], ['y', 'y', 'y']]
-        var z: number = 1
+      var l: list<list<string>> = [['x', 'x', 'x'], ['y', 'y', 'y']]
+      var z: number = 1
 
-        [l[1][2], z] = ['a', 20]
-        assert_equal([['x', 'x', 'x'], ['y', 'y', 'a']], l)
+      [l[1][2], z] = ['a', 20]
+      assert_equal([['x', 'x', 'x'], ['y', 'y', 'a']], l)
     enddef
     Foo()
   END
   v9.CheckSourceSuccess(lines)
+
+  lines =<< trim END
+    vim9script
+
+    var l: list<list<string>> = [['x', 'x', 'x'], ['y', 'y', 'y']]
+    var z: number = 1
+
+    [l[1][2], z] = ['a', 20]
+    assert_equal([['x', 'x', 'x'], ['y', 'y', 'a']], l)
+  END
+  v9.CheckSourceSuccess(lines)
+enddef
+
+" Test for assigning to a multi-dimensional dict item.
+def Test_dict_item_assign()
+  # This used to fail with the error "E1105: Cannot convert list to string"
+  # (Github issue #13485)
+  var lines =<< trim END
+    vim9script
+    def F()
+      var d: dict<dict<number>> = {a: {b: 0}}
+
+      for group in keys(d)
+        d['a']['b'] += 1
+      endfor
+      assert_equal({a: {b: 1}}, d)
+    enddef
+    F()
+  END
+  v9.CheckSourceSuccess(lines)
+
+  # This used to crash Vim
+  lines =<< trim END
+    vim9script
+    def F()
+      var d: dict<dict<number>> = {a: {b: 0}}
+      d['a']['b'] += 1
+      assert_equal({a: {b: 1}}, d)
+    enddef
+    F()
+  END
+  v9.CheckSourceSuccess(lines)
+
+  # Assignment at script level
+  lines =<< trim END
+    vim9script
+    var d: dict<dict<number>> = {a: {b: 0}}
+
+    for group in keys(d)
+      d['a']['b'] += 1
+    endfor
+    assert_equal({a: {b: 1}}, d)
+  END
+  v9.CheckSourceSuccess(lines)
 enddef
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 9d78ad0aae915bb35d54f4d6a893980f7ca49369..521f75fb171f7f991f67feae55ee09051d866d89 100644 (file)
@@ -560,7 +560,6 @@ def Test_disassemble_store_index()
         '\d LOAD $0\_s*' ..
         '\d MEMBER dd\_s*' ..
         '\d\+ USEDICT\_s*' ..
-        '\d\+ 2STRING stack\[-2\]\_s*' ..
         '\d\+ STOREINDEX any\_s*' ..
         '\d\+ RETURN void',
         res)
index cd512dabec741318d74908a13911eb246ab4bfa1..3a72a9cc92bd96fbe7f337664f790f34004a0fd4 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2091,
 /**/
     2090,
 /**/
index a4ed44951d1b3ececd00001261ccbf0206845c8e..8a44376848763a5a57cf8b3b8c5529a375170ccc 100644 (file)
@@ -2221,15 +2221,6 @@ compile_load_lhs(
                return FAIL;
        }
 
-       if (lhs->lhs_type->tt_type == VAR_DICT && var_start[varlen] == '[')
-       {
-           // If the lhs is a Dict variable and an item is accessed by "[",
-           // then need to convert the key into a string.  The top item in the
-           // type stack is the Dict and the second last item is the key.
-           if (may_generate_2STRING(-2, FALSE, cctx) == FAIL)
-               return FAIL;
-       }
-
        // Now we can properly check the type.  The variable is indexed, thus
        // we need the member type.  For a class or object we don't know the
        // type yet, it depends on what member is used.