patch 9.1.1002: Vim9: unknown func error with interface declaring func var
Commit:
https://github.com/vim/vim/commit/c10342da449155b874ddc4b4a5beb92159ee96b7
Author: Yegappan Lakshmanan <[email protected]>
Date: Sat Jan 11 09:39:01 2025 +0100
patch 9.1.1002: Vim9: unknown func error with interface declaring func var
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 <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 799230a98..c20de2533 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -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()
diff --git a/src/testdir/test_vim9_disassemble.vim
b/src/testdir/test_vim9_disassemble.vim
index 7746b23b4..2dc925a35 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 77128722b..f79eb15f8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1002,
/**/
1001,
/**/
diff --git a/src/vim9expr.c b/src/vim9expr.c
index cfdea7bc4..9a9603454 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -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;
}
}
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1tWX7A-004Pyr-3m%40256bit.org.