summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_vim9_class.vim
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2023-12-11 17:40:46 +0100
committerChristian Brabandt <cb@256bit.org>2023-12-11 17:40:46 +0100
commit9ed53752df1020a6881ac68d1bde2852c9a680aa (patch)
treea99975a155438cacfc942a073910e1e038ed8f5a /src/testdir/test_vim9_class.vim
parentfa920da283f6651083b40d0aa28a9eacd5116593 (diff)
patch 9.0.2156: Vim9: can use typealias in assignmentv9.0.2156
Problem: Vim9: can use typealias in an assignment Solution: Generate errors when class/typealias involved in the rhs of an assignment closes: #13637 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org> Generate errors when class/typealias involved in assignment.
Diffstat (limited to 'src/testdir/test_vim9_class.vim')
-rw-r--r--src/testdir/test_vim9_class.vim70
1 files changed, 61 insertions, 9 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 96d3ae58ab..84ea1cb357 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -3093,25 +3093,77 @@ def Test_closure_in_class()
v9.CheckSourceSuccess(lines)
enddef
-def Test_call_constructor_from_legacy()
+def Test_construct_object_from_legacy()
+ # Cannot directly invoke constructor from legacy
var lines =<< trim END
vim9script
- var newCalled = 'false'
+ var newCalled = false
class A
- def new()
- newCalled = 'true'
+ def new(arg: string)
+ newCalled = true
enddef
endclass
- export def F(options = {}): any
- return A
+ export def CreateA(...args: list<any>): A
+ return call(A.new, args)
enddef
- g:p = F()
- legacy call p.new()
- assert_equal('true', newCalled)
+ g:P = CreateA
+ legacy call g:P('some_arg')
+ assert_equal(true, newCalled)
+ unlet g:P
+ END
+ v9.CheckSourceSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+
+ var newCalled = false
+
+ class A
+ static def CreateA(options = {}): any
+ return A.new()
+ enddef
+ def new()
+ newCalled = true
+ enddef
+ endclass
+
+ g:P = A.CreateA
+ legacy call g:P()
+ assert_equal(true, newCalled)
+ unlet g:P
+ END
+ v9.CheckSourceSuccess(lines)
+
+ # This also tests invoking "new()" with "call"
+ lines =<< trim END
+ vim9script
+
+ var createdObject: any
+
+ class A
+ this.val1: number
+ this.val2: number
+ static def CreateA(...args: list<any>): any
+ createdObject = call(A.new, args)
+ return createdObject
+ enddef
+ endclass
+
+ g:P = A.CreateA
+ legacy call g:P(3, 5)
+ assert_equal(3, createdObject.val1)
+ assert_equal(5, createdObject.val2)
+ legacy call g:P()
+ assert_equal(0, createdObject.val1)
+ assert_equal(0, createdObject.val2)
+ legacy call g:P(7)
+ assert_equal(7, createdObject.val1)
+ assert_equal(0, createdObject.val2)
+ unlet g:P
END
v9.CheckSourceSuccess(lines)
enddef