Mercurial > vim
diff src/testdir/test_vim9_class.vim @ 34759:a14868d39709 v9.1.0257
patch 9.1.0257: Vim9: :call may not find imported class members
Commit: https://github.com/vim/vim/commit/f1750ca0c2ef91c6e4857655ca8fdf8dd8f5abb8
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Tue Apr 2 20:41:04 2024 +0200
patch 9.1.0257: Vim9: :call may not find imported class members
Problem: Vim9: :call may not find imported class members
(mityu)
Solution: Set the typval of an imported lval variable correctly
(Yegappan Lakshmanan)
fixes: #14334
closes: #14386
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 02 Apr 2024 21:00:04 +0200 |
parents | 1a411f737239 |
children | d4fb6ea26ae4 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -3121,6 +3121,28 @@ def Test_class_import() v9.CheckScriptSuccess(lines) enddef +" Test for importing a class into a legacy script and calling the class method +def Test_class_method_from_legacy_script() + var lines =<< trim END + vim9script + export class A + static var name: string = 'a' + static def SetName(n: string) + name = n + enddef + endclass + END + writefile(lines, 'Xvim9export.vim', 'D') + + lines =<< trim END + import './Xvim9export.vim' as vim9 + + call s:vim9.A.SetName('b') + call assert_equal('b', s:vim9.A.name) + END + v9.CheckScriptSuccess(lines) +enddef + " Test for implementing an imported interface def Test_implement_imported_interface() var lines =<< trim END @@ -3220,6 +3242,23 @@ def Test_abstract_class() endclass END v9.CheckSourceFailure(lines, 'E1359: Cannot define a "new" method in an abstract class', 4) + + # extending an abstract class with class methods and variables + lines =<< trim END + vim9script + abstract class A + static var s: string = 'vim' + static def Fn(): list<number> + return [10] + enddef + endclass + class B extends A + endclass + var b = B.new() + assert_equal('vim', A.s) + assert_equal([10], A.Fn()) + END + v9.CheckScriptSuccess(lines) enddef def Test_closure_in_class()