0
0
mirror of https://github.com/vim/vim.git synced 2025-10-07 05:54:16 -04:00

patch 9.0.1883: Vim9: Calling an interface method using a child object fails

Problem:  Vim9: Calling an interface method using a child object fails
Solution: Search methods of parent class

When a class implementing an interface is extended by another class and
a child class instance is passed to a function that accepts the
interface, calling an interface method doesn't work properly.

closes: #13053

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
Yegappan Lakshmanan
2023-09-08 19:12:03 +02:00
committed by Christian Brabandt
parent 11d2aeeca4
commit cc0bcf4c9f
3 changed files with 96 additions and 3 deletions

View File

@@ -4396,4 +4396,81 @@ def Test_class_member_access_using_object()
v9.CheckScriptSuccess(lines)
enddef
" Test for using a interface method using a child object
def Test_interface_method_from_child()
var lines =<< trim END
vim9script
interface A
def Foo(): string
endinterface
class B implements A
def Foo(): string
return 'foo'
enddef
endclass
class C extends B
def Bar(): string
return 'bar'
enddef
endclass
def T1(a: A)
assert_equal('foo', a.Foo())
enddef
def T2(b: B)
assert_equal('foo', b.Foo())
enddef
var c = C.new()
T1(c)
T2(c)
END
v9.CheckScriptSuccess(lines)
enddef
" Test for using an interface method using a child object when it is overridden
" by the child class.
" FIXME: This test fails.
" def Test_interface_overridden_method_from_child()
" var lines =<< trim END
" vim9script
"
" interface A
" def Foo(): string
" endinterface
"
" class B implements A
" def Foo(): string
" return 'b-foo'
" enddef
" endclass
"
" class C extends B
" def Bar(): string
" return 'bar'
" enddef
" def Foo(): string
" return 'c-foo'
" enddef
" endclass
"
" def T1(a: A)
" assert_equal('c-foo', a.Foo())
" enddef
"
" def T2(b: B)
" assert_equal('c-foo', b.Foo())
" enddef
"
" var c = C.new()
" T1(c)
" T2(c)
" END
" v9.CheckScriptSuccess(lines)
" enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker