]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1002: Vim9: unknown func error with interface declaring func var v9.1.1002
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 11 Jan 2025 08:39:01 +0000 (09:39 +0100)
committerChristian Brabandt <cb@256bit.org>
Sat, 11 Jan 2025 08:39:01 +0000 (09:39 +0100)
Problem:  Vim9: unknown function error with interface declaring a
          function variable (lifepillar)
Solution: Use correct instruction for getting interface member variables
          (Yegappan Lakshmanan)

fixes: #16345
closes: #16421

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_class.vim
src/testdir/test_vim9_disassemble.vim
src/version.c
src/vim9expr.c

index 799230a98b00c22c75f2199c9615cdfd20ce1792..c20de25337dc26065518417576224a6decab2a0f 100644 (file)
@@ -7257,6 +7257,31 @@ def Test_interface_extends_with_dup_members()
   v9.CheckSourceSuccess(lines)
 enddef
 
+" Test for implementing an interface with different ordering for the interface
+" member variables.
+def Test_implement_interface_with_different_variable_order()
+  var lines =<< trim END
+    vim9script
+
+    interface IX
+      var F: func(): string
+    endinterface
+
+    class X implements IX
+      var x: number
+      var F: func(): string = () => 'ok'
+    endclass
+
+    def Foo(ix: IX): string
+      return ix.F()
+    enddef
+
+    var x0 = X.new(0)
+    assert_equal('ok', Foo(x0))
+  END
+  v9.CheckSourceSuccess(lines)
+enddef
+
 " Test for using "any" type for a variable in a sub-class while it has a
 " concrete type in the interface
 def Test_implements_using_var_type_any()
index 7746b23b4146859020edb7d1272c85623b561b44..2dc925a3536a200f5d8ee89c6d41e346ebff869d 100644 (file)
@@ -3586,4 +3586,29 @@ def Test_disassemble_member_initializer()
   unlet g:instr
 enddef
 
+" Disassemble the code generated for accessing a interface member variable
+def Test_disassemble_interface_variable_access()
+  var lines =<< trim END
+    vim9script
+    interface IX
+      var F: func(): string
+    endinterface
+
+    def Foo(ix: IX): string
+      return ix.F()
+    enddef
+
+    g:instr = execute('disassemble Foo')
+  END
+  v9.CheckScriptSuccess(lines)
+  assert_match('<SNR>\d\+_Foo\_s*' ..
+    'return ix.F()\_s*' ..
+    '0 LOAD arg\[-1\]\_s*' ..
+    '1 ITF_MEMBER 0 on IX\_s*' ..
+    '2 PCALL top (argc 0)\_s*' ..
+    '3 PCALL end\_s*' ..
+    '4 RETURN', g:instr)
+  unlet g:instr
+enddef
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 77128722bdbd2258aa9f464b4b2eedf4e4b46209..f79eb15f84de958db9893c0608dccb73de5eb008 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1002,
 /**/
     1001,
 /**/
index cfdea7bc41387230c269472cc8710c2beceb08b6..9a96034543f7a1e9b1067bb69d77cd6da4f6427b 100644 (file)
@@ -392,8 +392,15 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
            }
            else
            {
-               if (generate_GET_OBJ_MEMBER(cctx, m_idx, ocm->ocm_type) ==
-                                                                       FAIL)
+               int status;
+
+               if (IS_INTERFACE(cl))
+                   status = generate_GET_ITF_MEMBER(cctx, cl, m_idx,
+                                                       ocm->ocm_type);
+               else
+                   status = generate_GET_OBJ_MEMBER(cctx, m_idx,
+                                                       ocm->ocm_type);
+               if (status == FAIL)
                    return FAIL;
            }
        }