comparison src/testdir/test_vim9_class.vim @ 33211:71a097aab64d v9.0.1883

patch 9.0.1883: Vim9: Calling an interface method using a child object fails Commit: https://github.com/vim/vim/commit/cc0bcf4c9f4133750f5ee99c685ba995a1b840fd Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Sep 8 19:12:03 2023 +0200 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>
author Christian Brabandt <cb@256bit.org>
date Fri, 08 Sep 2023 19:15:08 +0200
parents 36aebbf8389f
children 499ba27ba0f6
comparison
equal deleted inserted replaced
33210:039954b5721d 33211:71a097aab64d
4394 Foo() 4394 Foo()
4395 END 4395 END
4396 v9.CheckScriptSuccess(lines) 4396 v9.CheckScriptSuccess(lines)
4397 enddef 4397 enddef
4398 4398
4399 " Test for using a interface method using a child object
4400 def Test_interface_method_from_child()
4401 var lines =<< trim END
4402 vim9script
4403
4404 interface A
4405 def Foo(): string
4406 endinterface
4407
4408 class B implements A
4409 def Foo(): string
4410 return 'foo'
4411 enddef
4412 endclass
4413
4414 class C extends B
4415 def Bar(): string
4416 return 'bar'
4417 enddef
4418 endclass
4419
4420 def T1(a: A)
4421 assert_equal('foo', a.Foo())
4422 enddef
4423
4424 def T2(b: B)
4425 assert_equal('foo', b.Foo())
4426 enddef
4427
4428 var c = C.new()
4429 T1(c)
4430 T2(c)
4431 END
4432 v9.CheckScriptSuccess(lines)
4433 enddef
4434
4435 " Test for using an interface method using a child object when it is overridden
4436 " by the child class.
4437 " FIXME: This test fails.
4438 " def Test_interface_overridden_method_from_child()
4439 " var lines =<< trim END
4440 " vim9script
4441 "
4442 " interface A
4443 " def Foo(): string
4444 " endinterface
4445 "
4446 " class B implements A
4447 " def Foo(): string
4448 " return 'b-foo'
4449 " enddef
4450 " endclass
4451 "
4452 " class C extends B
4453 " def Bar(): string
4454 " return 'bar'
4455 " enddef
4456 " def Foo(): string
4457 " return 'c-foo'
4458 " enddef
4459 " endclass
4460 "
4461 " def T1(a: A)
4462 " assert_equal('c-foo', a.Foo())
4463 " enddef
4464 "
4465 " def T2(b: B)
4466 " assert_equal('c-foo', b.Foo())
4467 " enddef
4468 "
4469 " var c = C.new()
4470 " T1(c)
4471 " T2(c)
4472 " END
4473 " v9.CheckScriptSuccess(lines)
4474 " enddef
4475
4399 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 4476 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker