annotate src/testdir/test_vim9_class.vim @ 35172:c98f002b1fe4 default tip

runtime(doc): fix typo in usr_52.txt Commit: https://github.com/vim/vim/commit/b7258738f80f26be302a84a99f968b3bdc2f29bb Author: Christian Brabandt <cb@256bit.org> Date: Sun May 12 19:04:47 2024 +0200 runtime(doc): fix typo in usr_52.txt fixes: https://github.com/vim/vim/issues/14758 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 12 May 2024 19:15:08 +0200
parents 12afa965d56e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1 " Test Vim9 classes
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3 source check.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
4 import './vim9.vim' as v9
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
5
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
6 def Test_class_basic()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7 # Class supported only in "vim9script"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
8 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
9 class NotWorking
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
10 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
11 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
12 v9.CheckSourceFailure(lines, 'E1316: Class can only be defined in Vim9 script', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
13
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
14 # First character in a class name should be capitalized.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
15 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
16 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
17 class notWorking
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
18 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
19 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
20 v9.CheckSourceFailure(lines, 'E1314: Class name must start with an uppercase letter: notWorking', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
21
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
22 # Only alphanumeric characters are supported in a class name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
23 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
24 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
25 class Not@working
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
26 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
27 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
28 v9.CheckSourceFailure(lines, 'E1315: White space required after name: Not@working', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
29
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
30 # Unsupported keyword (instead of class)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
31 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
32 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
33 abstract noclass Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
34 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
35 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
36 v9.CheckSourceFailure(lines, 'E475: Invalid argument: noclass Something', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
37
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
38 # Only the complete word "class" should be recognized
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
39 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
40 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
41 abstract classy Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
42 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
43 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
44 v9.CheckSourceFailure(lines, 'E475: Invalid argument: classy Something', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
45
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
46 # The complete "endclass" should be specified.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
47 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
48 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
49 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
50 endcl
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
51 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
52 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: endcl', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
53
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
54 # Additional words after "endclass"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
55 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
56 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
57 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
58 endclass school's out
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
59 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
60 v9.CheckSourceFailure(lines, "E488: Trailing characters: school's out", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
61
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
62 # Additional commands after "endclass"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
63 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
64 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
65 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
66 endclass | echo 'done'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
67 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
68 v9.CheckSourceFailure(lines, "E488: Trailing characters: | echo 'done'", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
69
35062
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
70 # Additional command after "class name"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
71 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
72 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
73 class Something | var x = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
74 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
75 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
76 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = 10", 2)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
77
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
78 # Additional command after "object variable"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
79 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
80 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
81 class Something
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
82 var l: list<number> = [] | var y = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
83 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
84 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
85 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
86
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
87 # Additional command after "class variable"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
88 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
89 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
90 class Something
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
91 static var d = {a: 10} | var y = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
92 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
93 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
94 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
95
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
96 # Additional command after "object method"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
97 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
98 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
99 class Something
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
100 def Foo() | var y = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
101 enddef
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
102 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
103 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
104 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
105
35068
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
106 # Comments are allowed after an inline block
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
107 lines =<< trim END
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
108 vim9script
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
109 class Foo
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
110 static const bar = { # {{{
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
111 baz: 'qux'
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
112 } # }}}
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
113 endclass
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
114 assert_equal({baz: 'qux'}, Foo.bar)
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
115 END
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
116 v9.CheckSourceSuccess(lines)
60a7fae99560 patch 9.1.0378: Vim9: no comments allowed after class vars
Christian Brabandt <cb@256bit.org>
parents: 35062
diff changeset
117
34508
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
118 # Try to define a class with the same name as an existing variable
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
119 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
120 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
121 var Something: list<number> = [1]
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
122 class Thing
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
123 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
124 interface Api
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
125 endinterface
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
126 class Something extends Thing implements Api
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
127 var v1: string = ''
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
128 def Foo()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
129 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
130 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
131 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
132 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "Something"', 7)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
133
34344
be4389b04043 patch 9.1.0105: Style: typos found
Christian Brabandt <cb@256bit.org>
parents: 34112
diff changeset
134 # Use old "this." prefixed member variable declaration syntax (without initialization)
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
135 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
136 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
137 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
138 this.count: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
139 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
140 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
141 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.count: number', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
142
34344
be4389b04043 patch 9.1.0105: Style: typos found
Christian Brabandt <cb@256bit.org>
parents: 34112
diff changeset
143 # Use old "this." prefixed member variable declaration syntax (with initialization)
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
144 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
145 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
146 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
147 this.count: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
148 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
149 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
150 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.count: number = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
151
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
152 # Use old "this." prefixed member variable declaration syntax (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
153 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
154 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
155 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
156 this.count = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
157 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
158 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
159 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.count = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
160
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
161 # Use "this" without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
162 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
163 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
164 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
165 this
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
166 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
167 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
168 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
169
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
170 # Use "this." without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
171 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
172 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
173 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
174 this.
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
175 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
176 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
177 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
178
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
179 # Space between "this" and ".<variable>"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
180 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
181 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
182 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
183 this .count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
184 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
185 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
186 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this .count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
187
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
188 # Space between "this." and the member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
189 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
190 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
191 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
192 this. count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
193 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
194 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
195 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this. count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
196
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
197 # Use "that" instead of "this"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
198 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
199 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
200 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
201 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
202 that.count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
203 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
204 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
205 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: that.count', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
206
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
207 # Use "variable" instead of "var" for member variable declaration (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
208 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
209 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
210 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
211 variable count: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
212 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
213 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
214 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: variable count: number', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
215
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
216 # Use "variable" instead of "var" for member variable declaration (with initialization)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
217 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
218 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
219 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
220 variable count: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
221 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
222 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
223 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: variable count: number = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
224
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
225 # Use "variable" instead of "var" for member variable declaration (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
226 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
227 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
228 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
229 variable count = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
230 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
231 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
232 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: variable count = 42', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
233
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
234 # Use a non-existing member variable in new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
235 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
236 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
237 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
238 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
239 this.state = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
240 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
241 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
242 var obj = Something.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
243 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
244 v9.CheckSourceFailure(lines, 'E1326: Variable "state" not found in object "Something"', 1)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
245
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
246 # Space before ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
247 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
248 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
249 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
250 var count : number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
251 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
252 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
253 v9.CheckSourceFailure(lines, 'E1059: No white space allowed before colon: count : number', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
254
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
255 # No space after ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
256 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
257 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
258 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
259 var count:number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
260 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
261 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
262 v9.CheckSourceFailure(lines, "E1069: White space required after ':'", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
263
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
264 # Missing ":var" in a "var" member variable declaration (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
265 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
266 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
267 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
268 var: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
269 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
270 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
271 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: var: number', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
272
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
273 # Missing ":var" in a "var" member variable declaration (with initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
274 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
275 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
276 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
277 var: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
278 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
279 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
280 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: var: number = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
281
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
282 # Missing ":var" in a "var" member variable declaration (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
283 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
284 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
285 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
286 var = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
287 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
288 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
289 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: var = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
290
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
291 # Test for unsupported comment specifier
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
292 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
293 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
294 class Something
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
295 # comment
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
296 #{
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
297 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
298 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
299 v9.CheckSourceFailure(lines, 'E1170: Cannot use #{ to start a comment', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
300
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
301 # Test for using class as a bool
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
302 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
303 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
304 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
305 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
306 if A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
307 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
308 END
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33996
diff changeset
309 v9.CheckSourceFailure(lines, 'E1405: Class "A" cannot be used as a value', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
310
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
311 # Test for using object as a bool
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
312 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
313 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
314 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
315 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
316 var a = A.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
317 if a
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
318 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
319 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
320 v9.CheckSourceFailure(lines, 'E1320: Using an Object as a Number', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
321
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
322 # Test for using class as a float
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
323 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
324 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
325 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
326 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
327 sort([1.1, A], 'f')
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
328 END
33933
aceaf677dd92 patch 9.0.2163: Vim9: type can be assigned to list/dict
Christian Brabandt <cb@256bit.org>
parents: 33929
diff changeset
329 v9.CheckSourceFailure(lines, 'E1405: Class "A" cannot be used as a value', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
330
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
331 # Test for using object as a float
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
332 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
333 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
334 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
335 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
336 var a = A.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
337 sort([1.1, a], 'f')
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
338 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
339 v9.CheckSourceFailure(lines, 'E1322: Using an Object as a Float', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
340
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
341 # Test for using class as a string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
342 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
343 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
344 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
345 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
346 :exe 'call ' .. A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
347 END
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33996
diff changeset
348 v9.CheckSourceFailure(lines, 'E1405: Class "A" cannot be used as a value', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
349
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
350 # Test for using object as a string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
351 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
352 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
353 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
354 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
355 var a = A.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
356 :exe 'call ' .. a
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
357 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
358 v9.CheckSourceFailure(lines, 'E1324: Using an Object as a String', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
359
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
360 # Test creating a class with member variables and methods, calling a object
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
361 # method. Check for using type() and typename() with a class and an object.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
362 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
363 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
364
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
365 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
366 var lnum: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
367 var col: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
368
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
369 # make a nicely formatted string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
370 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
371 return $'({this.lnum}, {this.col})'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
372 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
373 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
374
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
375 # use the automatically generated new() method
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
376 var pos = TextPosition.new(2, 12)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
377 assert_equal(2, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
378 assert_equal(12, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
379
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
380 # call an object method
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
381 assert_equal('(2, 12)', pos.ToString())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
382
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
383 assert_equal(v:t_class, type(TextPosition))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
384 assert_equal(v:t_object, type(pos))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
385 assert_equal('class<TextPosition>', typename(TextPosition))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
386 assert_equal('object<TextPosition>', typename(pos))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
387 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
388 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
389
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
390 # When referencing object methods, space cannot be used after a "."
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
391 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
392 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
393 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
394 def Foo(): number
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
395 return 10
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
396 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
397 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
398 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
399 var v = a. Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
400 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
401 v9.CheckSourceFailure(lines, "E1202: No white space allowed after '.'", 8)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
402
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
403 # Using an object without specifying a method or a member variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
404 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
405 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
406 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
407 def Foo(): number
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
408 return 10
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
409 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
410 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
411 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
412 var v = a.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
413 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
414 v9.CheckSourceFailure(lines, 'E15: Invalid expression: "a."', 8)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
415
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
416 # Error when parsing the arguments of an object method.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
417 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
418 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
419 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
420 def Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
421 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
422 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
423 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
424 var v = a.Foo(,)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
425 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
426 v9.CheckSourceFailure(lines, 'E15: Invalid expression: "a.Foo(,)"', 7)
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
427
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
428 # Use a multi-line initialization for a member variable
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
429 lines =<< trim END
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
430 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
431 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
432 var y = {
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
433 X: 1
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
434 }
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
435 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
436 var a = A.new()
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
437 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
438 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
439 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
440
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
441 " Tests for object/class methods in a class
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
442 def Test_class_def_method()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
443 # Using the "public" keyword when defining an object method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
444 var lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
445 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
446 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
447 public def Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
448 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
449 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
450 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
451 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
452
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
453 # Using the "public" keyword when defining a class method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
454 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
455 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
456 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
457 public static def Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
458 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
459 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
460 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
461 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
462
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
463 # Using the "public" keyword when defining an object protected method
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
464 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
465 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
466 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
467 public def _Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
468 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
469 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
470 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
471 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
472
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
473 # Using the "public" keyword when defining a class protected method
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
474 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
475 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
476 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
477 public static def _Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
478 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
479 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
480 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
481 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
482
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
483 # Using a "def" keyword without an object method name
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
484 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
485 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
486 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
487 def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
488 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
489 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
490 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
491 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: def', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
492
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
493 # Using a "def" keyword without a class method name
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
494 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
495 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
496 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
497 static def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
498 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
499 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
500 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
501 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: static def', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
502 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
503
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
504 def Test_class_defined_twice()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
505 # class defined twice should fail
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
506 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
507 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
508 class There
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
509 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
510 class There
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
511 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
512 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
513 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "There"', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
514
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
515 # one class, reload same script twice is OK
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
516 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
517 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
518 class There
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
519 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
520 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
521 writefile(lines, 'XclassTwice.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
522 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
523 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
524 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
525
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
526 def Test_returning_null_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
527 # this was causing an internal error
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
528 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
529 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
530
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
531 class BufferList
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
532 def Current(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
533 return null_object
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
534 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
535 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
536
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
537 var buffers = BufferList.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
538 echo buffers.Current()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
539 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
540 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
541 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
542
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
543 def Test_using_null_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
544 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
545 @_ = null_class.member
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
546 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
547 v9.CheckDefExecAndScriptFailure(lines, ['E715: Dictionary required', 'E1363: Incomplete type'])
35088
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
548
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
549 # Test for using a null class as a value
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
550 lines =<< trim END
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
551 vim9script
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
552 echo empty(null_class)
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
553 END
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
554 v9.CheckSourceFailure(lines, 'E1405: Class "" cannot be used as a value', 2)
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
555
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
556 # Test for using a null class with string()
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
557 lines =<< trim END
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
558 vim9script
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
559 assert_equal('class [unknown]', string(null_class))
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
560 END
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
561 v9.CheckSourceSuccess(lines)
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
562
35095
12afa965d56e patch 9.1.0387: Vim9: null value tests not sufficient
Christian Brabandt <cb@256bit.org>
parents: 35088
diff changeset
563 # Test for using a null class with type() and typename()
35088
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
564 lines =<< trim END
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
565 vim9script
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
566 assert_equal(12, type(null_class))
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
567 assert_equal('class<Unknown>', typename(null_class))
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
568 END
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
569 v9.CheckSourceSuccess(lines)
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
570 enddef
30cc85d355c1 patch 9.1.0385: Vim9: crash with null_class and null_object
Christian Brabandt <cb@256bit.org>
parents: 35068
diff changeset
571
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
572 def Test_class_interface_wrong_end()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
573 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
574 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
575 abstract class SomeName
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
576 var member = 'text'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
577 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
578 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
579 v9.CheckSourceFailure(lines, 'E476: Invalid command: endinterface, expected endclass', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
580
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
581 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
582 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
583 export interface AnotherName
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
584 var member: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
585 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
586 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
587 v9.CheckSourceFailure(lines, 'E476: Invalid command: endclass, expected endinterface', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
588 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
589
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
590 def Test_object_not_set()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
591 # Use an uninitialized object in script context
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
592 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
593 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
594
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
595 class State
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
596 var value = 'xyz'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
597 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
598
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
599 var state: State
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
600 var db = {'xyz': 789}
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
601 echo db[state.value]
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
602 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
603 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 9)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
604
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
605 # Use an uninitialized object from a def function
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
606 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
607 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
608
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
609 class Class
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
610 var id: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
611 def Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
612 echo 'Method1' .. this.id
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
613 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
614 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
615
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
616 var obj: Class
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
617 def Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
618 obj.Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
619 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
620 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
621 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
622 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
623
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
624 # Pass an uninitialized object variable to a "new" function and try to call an
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
625 # object method.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
626 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
627 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
628
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
629 class Background
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
630 var background = 'dark'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
631 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
632
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
633 class Colorscheme
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
634 var _bg: Background
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
635
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
636 def GetBackground(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
637 return this._bg.background
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
638 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
639 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
640
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
641 var bg: Background # UNINITIALIZED
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
642 echo Colorscheme.new(bg).GetBackground()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
643 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
644 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
645
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
646 # TODO: this should not give an error but be handled at runtime
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
647 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
648 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
649
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
650 class Class
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
651 var id: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
652 def Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
653 echo 'Method1' .. this.id
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
654 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
655 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
656
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
657 var obj = null_object
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
658 def Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
659 obj.Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
660 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
661 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
662 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
663 v9.CheckSourceFailure(lines, 'E1363: Incomplete type', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
664 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
665
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
666 " Null object assignment and comparison
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
667 def Test_null_object_assign_compare()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
668 var lines =<< trim END
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
669 vim9script
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
670
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
671 var nullo = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
672 def F(): any
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
673 return nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
674 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
675 assert_equal('object<Unknown>', typename(F()))
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
676
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
677 var o0 = F()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
678 assert_true(o0 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
679 assert_true(o0 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
680
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
681 var o1: any = nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
682 assert_true(o1 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
683 assert_true(o1 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
684
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
685 def G()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
686 var x = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
687 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
688
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
689 class C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
690 endclass
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
691 var o2: C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
692 assert_true(o2 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
693 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
694
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
695 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
696 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
697
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
698 o2 = C.new()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
699 assert_true(o2 != null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
700
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
701 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
702 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
703 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
704 v9.CheckSourceSuccess(lines)
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
705 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
706
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
707 " Test for object member initialization and disassembly
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
708 def Test_class_member_initializer()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
709 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
710 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
711
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
712 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
713 var lnum: number = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
714 var col: number = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
715
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
716 # constructor with only the line number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
717 def new(lnum: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
718 this.lnum = lnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
719 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
720 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
721
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
722 var pos = TextPosition.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
723 assert_equal(3, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
724 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
725
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
726 var instr = execute('disassemble TextPosition.new')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
727 assert_match('new\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
728 '0 NEW TextPosition size \d\+\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
729 '\d PUSHNR 1\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
730 '\d STORE_THIS 0\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
731 '\d PUSHNR 1\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
732 '\d STORE_THIS 1\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
733 'this.lnum = lnum\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
734 '\d LOAD arg\[-1]\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
735 '\d PUSHNR 0\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
736 '\d LOAD $0\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
737 '\d\+ STOREINDEX object\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
738 '\d\+ RETURN object.*',
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
739 instr)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
740 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
741 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
742 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
743
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
744 def Test_member_any_used_as_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
745 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
746 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
747
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
748 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
749 var value: number = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
750 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
751
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
752 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
753 var inner: any
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
754 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
755
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
756 def F(outer: Outer)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
757 outer.inner.value = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
758 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
759
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
760 var inner_obj = Inner.new(0)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
761 var outer_obj = Outer.new(inner_obj)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
762 F(outer_obj)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
763 assert_equal(1, inner_obj.value)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
764 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
765 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
766
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
767 # Try modifying a protected variable using an "any" object
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
768 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
769 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
770
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
771 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
772 var _value: string = ''
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
773 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
774
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
775 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
776 var inner: any
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
777 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
778
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
779 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
780 outer.inner._value = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
781 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
782
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
783 var inner_obj = Inner.new('a')
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
784 var outer_obj = Outer.new(inner_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
785 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
786 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
787 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_value" in class "Inner"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
788
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
789 # Try modifying a non-existing variable using an "any" object
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
790 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
791 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
792
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
793 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
794 var value: string = ''
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
795 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
796
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
797 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
798 var inner: any
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
799 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
800
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
801 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
802 outer.inner.someval = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
803 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
804
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
805 var inner_obj = Inner.new('a')
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
806 var outer_obj = Outer.new(inner_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
807 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
808 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
809 v9.CheckSourceFailure(lines, 'E1326: Variable "someval" not found in object "Inner"', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
810 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
811
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
812 " Nested assignment to a object variable which is of another class type
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
813 def Test_assignment_nested_type()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
814 var lines =<< trim END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
815 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
816
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
817 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
818 public var value: number = 0
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
819 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
820
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
821 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
822 var inner: Inner
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
823 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
824
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
825 def F(outer: Outer)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
826 outer.inner.value = 1
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
827 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
828
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
829 def Test_assign_to_nested_typed_member()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
830 var inner = Inner.new(0)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
831 var outer = Outer.new(inner)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
832 F(outer)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
833 assert_equal(1, inner.value)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
834 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
835
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
836 Test_assign_to_nested_typed_member()
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
837
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
838 var script_inner = Inner.new(0)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
839 var script_outer = Outer.new(script_inner)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
840 script_outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
841 assert_equal(1, script_inner.value)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
842 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
843 v9.CheckSourceSuccess(lines)
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
844
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
845 # Assignment where target item is read only in :def
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
846 lines =<< trim END
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
847 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
848
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
849 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
850 var value: number = 0
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
851 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
852
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
853 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
854 var inner: Inner
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
855 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
856
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
857 def F(outer: Outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
858 outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
859 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
860
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
861 def Test_assign_to_nested_typed_member()
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
862 var inner = Inner.new(0)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
863 var outer = Outer.new(inner)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
864 F(outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
865 assert_equal(1, inner.value)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
866 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
867
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
868 Test_assign_to_nested_typed_member()
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
869 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
870 v9.CheckSourceFailure(lines, 'E1335: Variable "value" in class "Inner" is not writable', 1)
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
871
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
872 # Assignment where target item is read only script level
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
873 lines =<< trim END
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
874 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
875
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
876 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
877 var value: number = 0
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
878 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
879
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
880 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
881 var inner: Inner
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
882 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
883
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
884 def F(outer: Outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
885 outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
886 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
887
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
888 var script_inner = Inner.new(0)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
889 var script_outer = Outer.new(script_inner)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
890 script_outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
891 assert_equal(1, script_inner.value)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
892 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
893 v9.CheckSourceFailure(lines, 'E1335: Variable "value" in class "Inner" is not writable', 17)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
894 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
895
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
896 def Test_assignment_with_operator()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
897 # Use "+=" to assign to a object variable
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
898 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
899 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
900
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
901 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
902 public var x: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
903
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
904 def Add(n: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
905 this.x += n
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
906 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
907 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
908
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
909 var f = Foo.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
910 f.Add(17)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
911 assert_equal(20, f.x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
912
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
913 def AddToFoo(obj: Foo)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
914 obj.x += 3
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
915 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
916
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
917 AddToFoo(f)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
918 assert_equal(23, f.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
919 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
920 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
921 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
922
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
923 def Test_list_of_objects()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
924 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
925 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
926
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
927 class Foo
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
928 def Add()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
929 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
930 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
931
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
932 def ProcessList(fooList: list<Foo>)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
933 for foo in fooList
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
934 foo.Add()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
935 endfor
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
936 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
937
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
938 var l: list<Foo> = [Foo.new()]
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
939 ProcessList(l)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
940 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
941 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
942 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
943
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
944 def Test_expr_after_using_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
945 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
946 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
947
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
948 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
949 var label: string = ''
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
950 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
951
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
952 def Foo(): Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
953 var v = Something.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
954 echo 'in Foo(): ' .. typename(v)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
955 return v
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
956 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
957
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
958 Foo()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
959 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
960 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
961 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
962
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
963 def Test_class_default_new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
964 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
965 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
966
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
967 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
968 var lnum: number = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
969 var col: number = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
970 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
971
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
972 var pos = TextPosition.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
973 assert_equal(1, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
974 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
975
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
976 pos = TextPosition.new(v:none, v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
977 assert_equal(1, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
978 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
979
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
980 pos = TextPosition.new(3, 22)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
981 assert_equal(3, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
982 assert_equal(22, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
983
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
984 pos = TextPosition.new(v:none, 33)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
985 assert_equal(1, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
986 assert_equal(33, pos.col)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
987 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
988 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
989
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
990 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
991 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
992 class Person
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
993 var name: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
994 var age: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
995 var education: string = "unknown"
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
996
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
997 def new(this.name, this.age = v:none, this.education = v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
998 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
999 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1000
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1001 var piet = Person.new("Piet")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1002 assert_equal("Piet", piet.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1003 assert_equal(42, piet.age)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1004 assert_equal("unknown", piet.education)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1005
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1006 var chris = Person.new("Chris", 4, "none")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1007 assert_equal("Chris", chris.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1008 assert_equal(4, chris.age)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1009 assert_equal("none", chris.education)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1010 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1011 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1012
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1013 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1014 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1015 class Person
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1016 var name: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1017 var age: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1018 var education: string = "unknown"
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1019
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1020 def new(this.name, this.age = v:none, this.education = v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1021 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1022 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1023
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1024 var missing = Person.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1025 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1026 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: new', 11)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1027
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1028 # Using a specific value to initialize an instance variable in the new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1029 # method.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1030 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1031 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1032 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1033 var val: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1034 def new(this.val = 'a')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1035 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1036 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1037 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1038 v9.CheckSourceFailure(lines, "E1328: Constructor default value must be v:none: = 'a'", 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1039 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1040
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1041 def Test_class_new_with_object_member()
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1042 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1043 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1044
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1045 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1046 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1047 var num: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1048 def new(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1049 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1050 def newVals(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1051 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1052 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1053
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1054 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1055 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1056 var c = C.new('cats', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1057 assert_equal('cats', c.str)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1058 assert_equal(2, c.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1059
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1060 c = C.newVals('dogs', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1061 assert_equal('dogs', c.str)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1062 assert_equal(4, c.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1063 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1064 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1065 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1066 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1067
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1068 Check()
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1069 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1070 v9.CheckSourceSuccess(lines)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1071
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1072 lines =<< trim END
33379
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
1073 vim9script
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
1074
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
1075 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1076 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1077 var num: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1078 def new(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1079 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1080 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1081
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1082 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1083 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1084 var c = C.new(1, 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1085 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1086 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1087 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1088 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1089
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1090 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1091 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1092 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got number', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1093
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1094 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1095 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1096
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1097 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1098 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1099 var num: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1100 def newVals(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1101 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1102 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1103
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1104 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1105 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1106 var c = C.newVals('dogs', 'apes')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1107 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1108 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1109 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1110 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1111
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1112 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1113 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1114 v9.CheckSourceFailure(lines, 'E1013: Argument 2: type mismatch, expected number but got string', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1115
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1116 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1117 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1118
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1119 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1120 var str: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1121 def new(str: any)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1122 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1123 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1124
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1125 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1126 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1127 var c = C.new(1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1128 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1129 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1130 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1131 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1132
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1133 Check()
33326
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
1134 END
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
1135 v9.CheckSourceSuccess(lines)
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1136
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1137 # Try using "this." argument in a class method
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1138 lines =<< trim END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1139 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1140 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1141 var val = 10
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1142 static def Foo(this.val: number)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1143 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1144 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1145 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1146 v9.CheckSourceFailure(lines, 'E1390: Cannot use an object variable "this.val" except with the "new" method', 4)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1147
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1148 # Try using "this." argument in an object method
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1149 lines =<< trim END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1150 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1151 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1152 var val = 10
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1153 def Foo(this.val: number)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1154 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1155 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1156 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1157 v9.CheckSourceFailure(lines, 'E1390: Cannot use an object variable "this.val" except with the "new" method', 4)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1158 enddef
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1159
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1160 def Test_class_object_member_inits()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1161 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1162 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1163 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1164 var lnum: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1165 var col = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1166 var addcol: number = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1167 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1168
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1169 var pos = TextPosition.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1170 assert_equal(0, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1171 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1172 assert_equal(2, pos.addcol)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1173 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1174 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1175
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1176 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1177 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1178 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1179 var lnum
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1180 var col = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1181 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1182 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1183 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1184
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1185 # If the type is not specified for a member, then it should be set during
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1186 # object creation and not when defining the class.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1187 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1188 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1189
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1190 var init_count = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1191 def Init(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1192 init_count += 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1193 return 'foo'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1194 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1195
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1196 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1197 var str1 = Init()
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1198 var str2: string = Init()
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1199 var col = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1200 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1201
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1202 assert_equal(init_count, 0)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1203 var a = A.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1204 assert_equal(init_count, 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1205 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1206 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1207
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1208 # Test for initializing an object member with an unknown variable/type
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1209 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1210 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1211 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1212 var value = init_val
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1213 endclass
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1214 var a = A.new()
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1215 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1216 v9.CheckSourceFailure(lines, 'E1001: Variable not found: init_val', 1)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1217
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1218 # Test for initializing an object member with an special type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1219 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1220 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1221 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1222 var value: void
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1223 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1224 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1225 v9.CheckSourceFailure(lines, 'E1330: Invalid type for object variable: void', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1226 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1227
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1228 " Test for instance variable access
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1229 def Test_instance_variable_access()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1230 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1231 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1232 class Triple
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1233 var _one = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1234 var two = 2
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1235 public var three = 3
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1236
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1237 def GetOne(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1238 return this._one
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1239 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1240 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1241
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1242 var trip = Triple.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1243 assert_equal(1, trip.GetOne())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1244 assert_equal(2, trip.two)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1245 assert_equal(3, trip.three)
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1246 assert_fails('echo trip._one', 'E1333: Cannot access protected variable "_one" in class "Triple"')
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1247
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1248 assert_fails('trip._one = 11', 'E1333: Cannot access protected variable "_one" in class "Triple"')
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1249 assert_fails('trip.two = 22', 'E1335: Variable "two" in class "Triple" is not writable')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1250 trip.three = 33
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1251 assert_equal(33, trip.three)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1252
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
1253 assert_fails('trip.four = 4', 'E1326: Variable "four" not found in object "Triple"')
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1254 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1255 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1256
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1257 # Test for a public member variable name beginning with an underscore
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1258 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1259 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1260 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1261 public var _val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1262 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1263 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
1264 v9.CheckSourceFailure(lines, 'E1332: public variable name cannot start with underscore: public var _val = 10', 3)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1265
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1266 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1267 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1268
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1269 class MyCar
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1270 var make: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1271 var age = 5
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1272
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1273 def new(make_arg: string)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1274 this.make = make_arg
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1275 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1276
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1277 def GetMake(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1278 return $"make = {this.make}"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1279 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1280 def GetAge(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1281 return this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1282 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1283 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1284
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1285 var c = MyCar.new("abc")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1286 assert_equal('make = abc', c.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1287
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1288 c = MyCar.new("def")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1289 assert_equal('make = def', c.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1290
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1291 var c2 = MyCar.new("123")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1292 assert_equal('make = 123', c2.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1293
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1294 def CheckCar()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1295 assert_equal("make = def", c.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1296 assert_equal(5, c.GetAge())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1297 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1298 CheckCar()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1299 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1300 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1301
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1302 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1303 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1304
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1305 class MyCar
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1306 var make: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1307
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1308 def new(make_arg: string)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1309 this.make = make_arg
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1310 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1311 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1312
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1313 var c = MyCar.new("abc")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1314 var c = MyCar.new("def")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1315 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1316 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "c"', 12)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1317
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1318 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1319 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1320
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1321 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1322 var x: list<number> = []
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1323
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1324 def Add(n: number): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1325 this.x->add(n)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1326 return this
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1327 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1328 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1329
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1330 echo Foo.new().Add(1).Add(2).x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1331 echo Foo.new().Add(1).Add(2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1332 .x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1333 echo Foo.new().Add(1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1334 .Add(2).x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1335 echo Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1336 .Add(1).Add(2).x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1337 echo Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1338 .Add(1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1339 .Add(2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1340 .x
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1341 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1342 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1343
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1344 # Test for "public" cannot be abbreviated
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1345 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1346 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1347 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1348 pub var val = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1349 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1350 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1351 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: pub var val = 1', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1352
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1353 # Test for "public" keyword must be followed by "var" or "static".
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1354 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1355 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1356 class Something
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1357 public val = 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1358 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1359 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
1360 v9.CheckSourceFailure(lines, 'E1331: public must be followed by "var" or "static"', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1361
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1362 # Modify a instance variable using the class name in the script context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1363 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1364 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1365 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1366 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1367 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1368 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1369 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1370 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 5)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1371
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1372 # Read a instance variable using the class name in the script context
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1373 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1374 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1375 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1376 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1377 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1378 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1379 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1380 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 5)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1381
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1382 # Modify a instance variable using the class name in a def function
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
1383 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
1384 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1385 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1386 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1387 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1388 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1389 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1390 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1391 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1392 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1393 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1394
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1395 # Read a instance variable using the class name in a def function
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1396 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1397 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1398 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1399 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1400 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1401 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1402 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1403 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1404 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1405 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1406 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 1)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1407
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1408 # Access from child class extending a class:
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1409 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1410 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1411 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1412 var ro_obj_var = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1413 public var rw_obj_var = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1414 var _priv_obj_var = 30
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1415 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1416
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1417 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1418 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1419 var x: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1420 x = this.ro_obj_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1421 this.ro_obj_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1422 x = this.rw_obj_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1423 this.rw_obj_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1424 x = this._priv_obj_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1425 this._priv_obj_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1426 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1427 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1428
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1429 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1430 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1431 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1432 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1433 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1434
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1435 " Test for class variable access
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1436 def Test_class_variable_access()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1437 # Test for "static" cannot be abbreviated
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1438 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1439 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1440 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1441 stat var val = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1442 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1443 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1444 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: stat var val = 1', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1445
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1446 # Test for "static" cannot be followed by "public".
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1447 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1448 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1449 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1450 static public var val = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1451 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1452 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1453 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1454
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1455 # A readonly class variable cannot be modified from a child class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1456 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1457 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1458 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1459 static var ro_class_var = 40
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1460 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1461
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1462 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1463 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1464 A.ro_class_var = 50
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1465 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1466 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1467
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1468 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1469 b.Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1470 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1471 v9.CheckSourceFailure(lines, 'E1335: Variable "ro_class_var" in class "A" is not writable', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1472
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1473 # A protected class variable cannot be accessed from a child class
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1474 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1475 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1476 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1477 static var _priv_class_var = 60
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1478 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1479
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1480 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1481 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1482 var i = A._priv_class_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1483 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1484 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1485
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1486 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1487 b.Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1488 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1489 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_priv_class_var" in class "A"', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1490
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1491 # A protected class variable cannot be modified from a child class
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1492 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1493 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1494 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1495 static var _priv_class_var = 60
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1496 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1497
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1498 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1499 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1500 A._priv_class_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1501 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1502 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1503
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1504 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1505 b.Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1506 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1507 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_priv_class_var" in class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1508
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1509 # Access from child class extending a class and from script context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1510 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1511 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1512 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1513 static var ro_class_var = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1514 public static var rw_class_var = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1515 static var _priv_class_var = 30
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1516 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1517
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1518 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1519 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1520 var x: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1521 x = A.ro_class_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1522 assert_equal(10, x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1523 x = A.rw_class_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1524 assert_equal(25, x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1525 A.rw_class_var = 20
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1526 assert_equal(20, A.rw_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1527 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1528 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1529
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1530 assert_equal(10, A.ro_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1531 assert_equal(20, A.rw_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1532 A.rw_class_var = 25
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1533 assert_equal(25, A.rw_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1534 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1535 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1536 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1537 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1538 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1539
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1540 def Test_class_object_compare()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1541 var class_lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1542 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1543 class Item
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1544 var nr = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1545 var name = 'xx'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1546 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1547 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1548
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1549 # used at the script level and in a compiled function
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1550 var test_lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1551 var i1 = Item.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1552 assert_equal(i1, i1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1553 assert_true(i1 is i1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1554 var i2 = Item.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1555 assert_equal(i1, i2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1556 assert_false(i1 is i2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1557 var i3 = Item.new(0, 'xx')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1558 assert_equal(i1, i3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1559
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1560 var io1 = Item.new(1, 'xx')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1561 assert_notequal(i1, io1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1562 var io2 = Item.new(0, 'yy')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1563 assert_notequal(i1, io2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1564 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1565
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1566 v9.CheckSourceSuccess(class_lines + test_lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1567 v9.CheckSourceSuccess(
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1568 class_lines + ['def Test()'] + test_lines + ['enddef', 'Test()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1569
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1570 for op in ['>', '>=', '<', '<=', '=~', '!~']
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1571 var op_lines = [
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1572 'var i1 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1573 'var i2 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1574 'echo i1 ' .. op .. ' i2',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1575 ]
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1576 v9.CheckSourceFailure(class_lines + op_lines, 'E1153: Invalid operation for object', 8)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1577 v9.CheckSourceFailure(class_lines
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1578 + ['def Test()'] + op_lines + ['enddef', 'Test()'], 'E1153: Invalid operation for object')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1579 endfor
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1580 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1581
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1582 def Test_object_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1583 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1584 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1585
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1586 class One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1587 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1588 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1589 class Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1590 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1591 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1592 class TwoMore extends Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1593 var more = 9
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1594 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1595
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1596 var o: One = One.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1597 var t: Two = Two.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1598 var m: TwoMore = TwoMore.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1599 var tm: Two = TwoMore.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1600
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1601 t = m
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1602 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1603 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1604
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1605 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1606 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1607
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1608 class One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1609 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1610 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1611 class Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1612 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1613 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1614
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1615 var o: One = Two.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1616 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1617 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected object<One> but got object<Two>', 10)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1618
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1619 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1620 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1621
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1622 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1623 def GetMember(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1624 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1625 class Two implements One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1626 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1627 def GetMember(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1628 return this.one
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1629 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1630 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1631
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1632 var o: One = Two.new(5)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1633 assert_equal(5, o.GetMember())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1634 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1635 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1636
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1637 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1638 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1639
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1640 class Num
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1641 var n: number = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1642 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1643
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1644 def Ref(name: string): func(Num): Num
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1645 return (arg: Num): Num => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1646 return eval(name)(arg)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1647 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1648 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1649
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1650 const Fn = Ref('Double')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1651 var Double = (m: Num): Num => Num.new(m.n * 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1652
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1653 echo Fn(Num.new(4))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1654 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1655 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1656 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1657
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1658 def Test_class_member()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1659 # check access rules
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1660 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1661 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1662 class TextPos
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1663 var lnum = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1664 var col = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1665 static var counter = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1666 static var _secret = 7
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1667 public static var anybody = 42
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1668
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1669 static def AddToCounter(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1670 counter += nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1671 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1672 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1673
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1674 assert_equal(0, TextPos.counter)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1675 TextPos.AddToCounter(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1676 assert_equal(3, TextPos.counter)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1677 assert_fails('echo TextPos.noSuchMember', 'E1337: Class variable "noSuchMember" not found in class "TextPos"')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1678
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1679 def GetCounter(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1680 return TextPos.counter
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1681 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1682 assert_equal(3, GetCounter())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1683
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1684 assert_fails('TextPos.noSuchMember = 2', 'E1337: Class variable "noSuchMember" not found in class "TextPos"')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1685 assert_fails('TextPos.counter = 5', 'E1335: Variable "counter" in class "TextPos" is not writable')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1686 assert_fails('TextPos.counter += 5', 'E1335: Variable "counter" in class "TextPos" is not writable')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1687
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1688 assert_fails('echo TextPos._secret', 'E1333: Cannot access protected variable "_secret" in class "TextPos"')
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1689 assert_fails('TextPos._secret = 8', 'E1333: Cannot access protected variable "_secret" in class "TextPos"')
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1690
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1691 assert_equal(42, TextPos.anybody)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1692 TextPos.anybody = 12
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1693 assert_equal(12, TextPos.anybody)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1694 TextPos.anybody += 5
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1695 assert_equal(17, TextPos.anybody)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1696 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1697 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1698
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1699 # example in the help
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1700 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1701 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1702 class OtherThing
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1703 var size: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1704 static var totalSize: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1705
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1706 def new(this.size)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1707 totalSize += this.size
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1708 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1709 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1710 assert_equal(0, OtherThing.totalSize)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1711 var to3 = OtherThing.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1712 assert_equal(3, OtherThing.totalSize)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1713 var to7 = OtherThing.new(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1714 assert_equal(10, OtherThing.totalSize)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1715 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1716 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1717
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1718 # using static class member twice
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1719 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1720 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1721
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1722 class HTML
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1723 static var author: string = 'John Doe'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1724
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1725 static def MacroSubstitute(s: string): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1726 return substitute(s, '{{author}}', author, 'gi')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1727 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1728 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1729
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1730 assert_equal('some text', HTML.MacroSubstitute('some text'))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1731 assert_equal('some text', HTML.MacroSubstitute('some text'))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1732 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1733 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1734
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1735 # access protected member in lambda
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1736 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1737 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1738
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1739 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1740 var _x: number = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1741
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1742 def Add(n: number): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1743 const F = (): number => this._x + n
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1744 return F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1745 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1746 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1747
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1748 var foo = Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1749 assert_equal(5, foo.Add(5))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1750 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1751 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1752
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1753 # access protected member in lambda body
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1754 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1755 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1756
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1757 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1758 var _x: number = 6
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1759
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1760 def Add(n: number): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1761 var Lam = () => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1762 this._x = this._x + n
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1763 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1764 Lam()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1765 return this._x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1766 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1767 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1768
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1769 var foo = Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1770 assert_equal(13, foo.Add(7))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1771 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1772 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1773
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1774 # check shadowing
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1775 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1776 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1777
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1778 class Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1779 static var count = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1780 def Method(count: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1781 echo count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1782 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1783 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1784
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1785 var s = Some.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1786 s.Method(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1787 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1788 v9.CheckSourceFailure(lines, 'E1340: Argument already declared in the class: count', 5)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1789
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
1790 # Use a local variable in a method with the same name as a class variable
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1791 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1792 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1793
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1794 class Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1795 static var count = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1796 def Method(arg: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1797 var count = 3
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1798 echo arg count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1799 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1800 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1801
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1802 var s = Some.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1803 s.Method(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1804 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1805 v9.CheckSourceFailure(lines, 'E1341: Variable already declared in the class: count', 1)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1806
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1807 # Test for using an invalid type for a member variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1808 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1809 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1810 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1811 var val: xxx
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1812 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1813 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1814 v9.CheckSourceFailure(lines, 'E1010: Type not recognized: xxx', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1815
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1816 # Test for setting a member on a null object
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1817 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1818 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1819 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1820 public var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1821 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1822
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1823 def F()
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1824 var obj: A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1825 obj.val = ""
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1826 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1827 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1828 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1829 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1830
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1831 # Test for accessing a member on a null object
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1832 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1833 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1834 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1835 var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1836 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1837
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1838 def F()
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1839 var obj: A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1840 echo obj.val
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1841 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1842 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1843 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1844 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1845
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1846 # Test for setting a member on a null object, at script level
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1847 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1848 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1849 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1850 public var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1851 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1852
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1853 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1854 obj.val = ""
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1855 END
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
1856 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 7)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1857
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1858 # Test for accessing a member on a null object, at script level
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1859 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1860 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1861 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1862 var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1863 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1864
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1865 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1866 echo obj.val
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1867 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1868 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 7)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1869
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1870 # Test for no space before or after the '=' when initializing a member
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1871 # variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1872 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1873 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1874 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1875 var val: number= 10
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1876 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1877 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1878 v9.CheckSourceFailure(lines, "E1004: White space required before and after '='", 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1879 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1880 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1881 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1882 var val: number =10
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1883 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1884 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1885 v9.CheckSourceFailure(lines, "E1004: White space required before and after '='", 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1886
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1887 # Access a non-existing member
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1888 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1889 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1890 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1891 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1892 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1893 var v = a.bar
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1894 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
1895 v9.CheckSourceFailure(lines, 'E1326: Variable "bar" not found in object "A"', 5)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1896 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1897
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1898 " These messages should show the defining class of the variable (base class),
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1899 " not the class that did the reference (super class)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1900 def Test_defining_class_message()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1901 var lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1902 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1903
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1904 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1905 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1906 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1907
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1908 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1909 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1910
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1911 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1912 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1913 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1914 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Base"', 11)
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1915 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1916 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1917
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1918 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1919 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1920 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1921
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1922 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1923 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1924
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1925 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1926 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1927 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1928 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1929 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1930 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1931 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Base"', 2)
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1932 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1933 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1934
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1935 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1936 var v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1937 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1938
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1939 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1940 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1941
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1942 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1943 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1944 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1945 v9.CheckSourceFailure(lines, 'E1335: Variable "v1" in class "Base" is not writable', 11)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1946 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1947 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1948
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1949 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1950 var v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1951 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1952
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1953 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1954 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1955
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1956 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1957 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1958 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1959 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1960 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1961 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1962
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1963 # Attempt to read a protected variable that is in the middle
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1964 # of the class hierarchy.
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1965 v9.CheckSourceFailure(lines, 'E1335: Variable "v1" in class "Base" is not writable', 2)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1966 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1967 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1968
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1969 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1970 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1971
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1972 class Base extends Base0
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1973 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1974 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1975
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1976 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1977 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1978
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1979 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1980 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1981 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1982 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1983 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1984 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1985 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Base"', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1986
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1987 # Attempt to read a protected variable that is at the start
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1988 # of the class hierarchy.
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1989 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1990 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1991
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1992 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1993 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1994
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1995 class Base extends Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1996 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1997
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1998 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1999 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2000 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2001
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2002 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2003 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2004 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2005 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2006 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2007 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
2008 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Child"', 2)
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2009 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
2010
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2011 func Test_class_garbagecollect()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2012 let lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2013 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2014
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2015 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2016 var p = [2, 3]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2017 static var pl = ['a', 'b']
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2018 static var pd = {a: 'a', b: 'b'}
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2019 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2020
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2021 echo Point.pl Point.pd
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2022 call test_garbagecollect_now()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2023 echo Point.pl Point.pd
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2024 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2025 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2026
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2027 let lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2028 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2029
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2030 interface View
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2031 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2032
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2033 class Widget
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2034 var view: View
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2035 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2036
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2037 class MyView implements View
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2038 var widget: Widget
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2039
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2040 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2041 # this will result in a circular reference to this object
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2042 var widget = Widget.new(this)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2043 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2044 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2045
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2046 var view = MyView.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2047
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2048 # overwrite "view", will be garbage-collected next
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2049 view = MyView.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2050 test_garbagecollect_now()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2051 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2052 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2053 endfunc
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2054
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2055 " Test interface garbage collection
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2056 func Test_interface_garbagecollect()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2057 let lines =<< trim END
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2058 vim9script
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2059
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2060 interface I
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2061 var ro_obj_var: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
2062
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2063 def ObjFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2064 endinterface
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2065
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2066 class A implements I
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2067 static var ro_class_var: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2068 public static var rw_class_var: number = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2069 static var _priv_class_var: number = 30
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2070 var ro_obj_var: number = 40
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2071 var _priv_obj_var: number = 60
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2072
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2073 static def _ClassBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2074 return _priv_class_var
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2075 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2076
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2077 static def ClassFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2078 return ro_class_var + rw_class_var + A._ClassBar()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2079 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2080
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2081 def _ObjBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2082 return this._priv_obj_var
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2083 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2084
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2085 def ObjFoo(): number
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2086 return this.ro_obj_var + this._ObjBar()
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2087 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2088 endclass
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2089
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2090 assert_equal(60, A.ClassFoo())
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2091 var o = A.new()
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2092 assert_equal(100, o.ObjFoo())
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2093 test_garbagecollect_now()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2094 assert_equal(60, A.ClassFoo())
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2095 assert_equal(100, o.ObjFoo())
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2096 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2097 call v9.CheckSourceSuccess(lines)
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2098 endfunc
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2099
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2100 def Test_class_method()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2101 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2102 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2103 class Value
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2104 var value = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2105 static var objects = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2106
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2107 def new(v: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2108 this.value = v
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2109 ++objects
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2110 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2111
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2112 static def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2113 return objects
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2114 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2115 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2116
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2117 assert_equal(0, Value.GetCount())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2118 var v1 = Value.new(2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2119 assert_equal(1, Value.GetCount())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2120 var v2 = Value.new(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2121 assert_equal(2, Value.GetCount())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2122 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2123 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2124
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2125 # Test for cleaning up after a class definition failure when using class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2126 # functions.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2127 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2128 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2129 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2130 static def Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2131 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2132 aaa
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2133 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2134 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2135 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: aaa', 5)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2136
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2137 # Test for calling a class method from another class method without the class
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2138 # name prefix.
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2139 lines =<< trim END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2140 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2141 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2142 static var myList: list<number> = [1]
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2143 static def Foo(n: number)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2144 myList->add(n)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2145 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2146 static def Bar()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2147 Foo(2)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2148 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2149 def Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2150 Foo(3)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2151 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2152 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2153 A.Bar()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2154 var a = A.new()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2155 a.Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2156 assert_equal([1, 2, 3], A.myList)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2157 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2158 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2159 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2160
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2161 def Test_class_defcompile()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2162 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2163 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2164
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2165 class C
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2166 def Fo(i: number): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2167 return i
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2168 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2169 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2170
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2171 defcompile C.Fo
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2172 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2173 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected string but got number', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2174
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2175 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2176 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2177
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2178 class C
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2179 static def Fc(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2180 return 'x'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2181 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2182 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2183
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2184 defcompile C.Fc
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2185 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2186 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2187
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2188 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2189 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2190
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2191 class C
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2192 static def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2193 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2194 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2195
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2196 defcompile C.new
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2197 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2198 v9.CheckSourceFailure(lines, 'E1370: Cannot define a "new" method as static', 5)
33068
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
2199
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2200 # Trying to compile a function using a non-existing class variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2201 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2202 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2203 defcompile x.Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2204 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2205 v9.CheckSourceFailure(lines, 'E475: Invalid argument: x.Foo()', 2)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2206
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2207 # Trying to compile a function using a variable which is not a class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2208 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2209 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2210 var x: number
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2211 defcompile x.Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2212 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2213 v9.CheckSourceFailure(lines, 'E475: Invalid argument: x.Foo()', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2214
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2215 # Trying to compile a function without specifying the name
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2216 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2217 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2218 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2219 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2220 defcompile A.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2221 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2222 v9.CheckSourceFailure(lines, 'E475: Invalid argument: A.', 4)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2223
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2224 # Trying to compile a non-existing class object member function
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2225 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2226 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2227 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2228 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2229 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2230 defcompile a.Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2231 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
2232 v9.CheckSourceFailureList(lines, ['E1326: Variable "Foo" not found in object "A"', 'E475: Invalid argument: a.Foo()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2233 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2234
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2235 def Test_class_object_to_string()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2236 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2237 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2238 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2239 var lnum = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2240 var col = 22
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2241 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2242
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2243 assert_equal("class TextPosition", string(TextPosition))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2244
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2245 var pos = TextPosition.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2246 assert_equal("object of TextPosition {lnum: 1, col: 22}", string(pos))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2247 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2248 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2249 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2250
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2251 def Test_interface_basics()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2252 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2253 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2254 interface Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2255 var ro_var: list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2256 def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2257 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2258 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2259 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2260
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2261 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2262 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2263 static var count = 7
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2264 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2265 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2266 v9.CheckSourceFailure(lines, 'E1342: Interface can only be defined in Vim9 script', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2267
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2268 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2269 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2270
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2271 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2272 var value: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2273 def Method(value: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2274 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2275 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2276 # The argument name and the object member name are the same, but this is not a
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2277 # problem because object members are always accessed with the "this." prefix.
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2278 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2279
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2280 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2281 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2282 interface somethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2283 static var count = 7
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2284 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2285 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2286 v9.CheckSourceFailure(lines, 'E1343: Interface name must start with an uppercase letter: somethingWrong', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2287
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2288 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2289 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2290 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2291 var value: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2292 var count = 7
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2293 def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2294 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2295 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2296 v9.CheckSourceFailure(lines, 'E1344: Cannot initialize a variable in an interface', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2297
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2298 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2299 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2300 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2301 var value: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2302 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2303 def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2304 return 5
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2305 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2306 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2307 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2308 v9.CheckSourceFailure(lines, 'E1345: Not a valid command in an interface: return 5', 6)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2309
35062
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2310 # Additional commands after "interface name"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2311 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2312 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2313 interface Something | var x = 10 | var y = 20
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2314 endinterface
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2315 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2316 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = 10", 2)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2317
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2318 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2319 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2320 export interface EnterExit
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2321 def Enter(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2322 def Exit(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2323 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2324 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2325 writefile(lines, 'XdefIntf.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2326
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2327 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2328 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2329 import './XdefIntf.vim' as defIntf
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2330 export def With(ee: defIntf.EnterExit, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2331 ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2332 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2333 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2334 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2335 ee.Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2336 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2337 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2338 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2339 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2340
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2341 var imported =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2342 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2343 export abstract class EnterExit
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2344 def Enter(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2345 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2346 def Exit(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2347 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2348 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2349 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2350 writefile(imported, 'XdefIntf2.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2351
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2352 lines[1] = " import './XdefIntf2.vim' as defIntf"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2353 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2354 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2355
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2356 " Test for using string() with an interface
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2357 def Test_interface_to_string()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2358 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2359 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2360 interface Intf
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2361 def Method(nr: number)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2362 endinterface
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2363 assert_equal("interface Intf", string(Intf))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2364 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2365 v9.CheckSourceSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2366 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2367
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2368 def Test_class_implements_interface()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2369 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2370 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2371
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2372 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2373 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2374 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2375 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2376
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2377 class SomeImpl implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2378 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2379 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2380 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2381 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2382 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2383
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2384 interface Another
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2385 var member: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2386 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2387
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2388 class AnotherImpl implements Some, Another
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2389 var member = 'abc'
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2390 var count = 20
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2391 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2392 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2393 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2394 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2395 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2396 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2397
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2398 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2399 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2400
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2401 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2402 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2403 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2404
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2405 class SomeImpl implements Some implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2406 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2407 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2408 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2409 v9.CheckSourceFailure(lines, 'E1350: Duplicate "implements"', 7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2410
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2411 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2412 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2413
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2414 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2415 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2416 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2417
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2418 class SomeImpl implements Some, Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2419 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2420 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2421 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2422 v9.CheckSourceFailure(lines, 'E1351: Duplicate interface after "implements": Some', 7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2423
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2424 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2425 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2426
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2427 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2428 var counter: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2429 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2430 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2431
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2432 class SomeImpl implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2433 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2434 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2435 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2436 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2437 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2438 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2439 v9.CheckSourceFailure(lines, 'E1348: Variable "counter" of interface "Some" is not implemented', 13)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2440
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2441 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2442 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2443
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2444 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2445 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2446 def Methods(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2447 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2448
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2449 class SomeImpl implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2450 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2451 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2452 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2453 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2454 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2455 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2456 v9.CheckSourceFailure(lines, 'E1349: Method "Methods" of interface "Some" is not implemented', 13)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2457
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2458 # Check different order of members in class and interface works.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2459 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2460 vim9script
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2461
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2462 interface Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2463 var label: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2464 var errpos: number
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2465 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2466
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2467 # order of members is opposite of interface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2468 class Failure implements Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2469 public var lnum: number = 5
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2470 var errpos: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2471 var label: string = 'label'
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2472 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2473
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2474 def Test()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2475 var result: Result = Failure.new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2476
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2477 assert_equal('label', result.label)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2478 assert_equal(42, result.errpos)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2479 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2480
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2481 Test()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2482 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2483 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2484
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2485 # Interface name after "extends" doesn't end in a space or NUL character
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2486 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2487 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2488 interface A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2489 endinterface
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2490 class B extends A"
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2491 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2492 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2493 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A"', 4)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2494
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2495 # Trailing characters after a class name
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2496 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2497 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2498 class A bbb
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2499 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2500 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2501 v9.CheckSourceFailure(lines, 'E488: Trailing characters: bbb', 2)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2502
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2503 # using "implements" with a non-existing class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2504 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2505 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2506 class A implements B
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2507 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2508 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2509 v9.CheckSourceFailure(lines, 'E1346: Interface name not found: B', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2510
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2511 # using "implements" with a regular class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2512 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2513 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2514 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2515 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2516 class B implements A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2517 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2518 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2519 v9.CheckSourceFailure(lines, 'E1347: Not a valid interface: A', 5)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2520
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2521 # using "implements" with a variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2522 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2523 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2524 var T: number = 10
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2525 class A implements T
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2526 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2527 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2528 v9.CheckSourceFailure(lines, 'E1347: Not a valid interface: T', 4)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2529
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2530 # implements should be followed by a white space
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2531 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2532 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2533 interface A
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2534 endinterface
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2535 class B implements A;
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2536 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2537 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2538 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A;', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2539
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2540 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2541 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2542
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2543 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2544 def IsEven(nr: number): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2545 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2546 class Two implements One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2547 def IsEven(nr: number): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2548 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2549 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2550 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2551 v9.CheckSourceFailure(lines, 'E1383: Method "IsEven": type mismatch, expected func(number): bool but got func(number): string', 9)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2552
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2553 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2554 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2555
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2556 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2557 def IsEven(nr: number): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2558 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2559 class Two implements One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2560 def IsEven(nr: bool): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2561 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2562 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2563 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2564 v9.CheckSourceFailure(lines, 'E1383: Method "IsEven": type mismatch, expected func(number): bool but got func(bool): bool', 9)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2565
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2566 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2567 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2568
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2569 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2570 def IsEven(nr: number): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2571 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2572 class Two implements One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2573 def IsEven(nr: number, ...extra: list<number>): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2574 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2575 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2576 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2577 v9.CheckSourceFailure(lines, 'E1383: Method "IsEven": type mismatch, expected func(number): bool but got func(number, ...list<number>): bool', 9)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2578
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2579 # access superclass interface members from subclass, mix variable order
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2580 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2581 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2582
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2583 interface I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2584 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2585 var mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2586 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2587
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2588 # NOTE: the order is swapped
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2589 class A implements I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2590 var mvar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2591 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2592 public static var svar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2593 public static var svar1: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2594 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2595 svar1 = 11
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2596 svar2 = 12
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2597 this.mvar1 = 111
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2598 this.mvar2 = 112
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2599 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2600 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2601
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2602 class B extends A
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2603 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2604 this.mvar1 = 121
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2605 this.mvar2 = 122
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2606 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2607 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2608
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2609 class C extends B
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2610 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2611 this.mvar1 = 131
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2612 this.mvar2 = 132
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2613 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2614 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2615
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2616 def F2(i: I1): list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2617 return [ i.mvar1, i.mvar2 ]
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2618 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2619
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2620 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2621 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2622 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2623
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2624 assert_equal([111, 112], F2(oa))
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2625 assert_equal([121, 122], F2(ob))
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2626 assert_equal([131, 132], F2(oc))
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2627 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2628 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2629
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2630 # Access superclass interface members from subclass, mix variable order.
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2631 # Two interfaces, one on A, one on B; each has both kinds of variables
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2632 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2633 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2634
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2635 interface I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2636 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2637 var mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2638 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2639
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2640 interface I2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2641 var mvar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2642 var mvar4: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2643 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2644
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2645 class A implements I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2646 public static var svar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2647 public static var svar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2648 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2649 var mvar2: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2650 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2651 svar1 = 11
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2652 svar2 = 12
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2653 this.mvar1 = 111
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2654 this.mvar2 = 112
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2655 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2656 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2657
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2658 class B extends A implements I2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2659 static var svar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2660 static var svar4: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2661 var mvar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2662 var mvar4: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2663 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2664 svar3 = 23
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2665 svar4 = 24
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2666 this.mvar1 = 121
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2667 this.mvar2 = 122
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2668 this.mvar3 = 123
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2669 this.mvar4 = 124
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2670 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2671 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2672
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2673 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2674 public static var svar5: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2675 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2676 svar5 = 1001
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2677 this.mvar1 = 131
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2678 this.mvar2 = 132
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2679 this.mvar3 = 133
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2680 this.mvar4 = 134
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2681 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2682 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2683
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2684 def F2(i: I1): list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2685 return [ i.mvar1, i.mvar2 ]
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2686 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2687
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2688 def F4(i: I2): list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2689 return [ i.mvar3, i.mvar4 ]
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2690 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2691
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2692 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2693 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2694 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2695
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2696 assert_equal([[111, 112]], [F2(oa)])
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2697 assert_equal([[121, 122], [123, 124]], [F2(ob), F4(ob)])
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2698 assert_equal([[131, 132], [133, 134]], [F2(oc), F4(oc)])
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2699 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2700 v9.CheckSourceSuccess(lines)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2701
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2702 # Using two interface names without a space after the ","
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2703 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2704 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2705 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2706 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2707 interface B
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2708 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2709 class C implements A,B
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2710 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2711 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2712 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A,B', 6)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2713
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2714 # No interface name after a comma
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2715 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2716 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2717 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2718 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2719 class B implements A,
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2720 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2721 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2722 v9.CheckSourceFailure(lines, 'E1389: Missing name after implements', 4)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2723
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2724 # No interface name after implements
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2725 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2726 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2727 class A implements
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2728 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2729 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2730 v9.CheckSourceFailure(lines, 'E1389: Missing name after implements', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2731 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2732
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2733 def Test_call_interface_method()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2734 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2735 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2736 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2737 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2738 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2739
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2740 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2741 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2742 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2743 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2744 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2745
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2746 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2747 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2748 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2749
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2750 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2751 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2752 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2753 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2754 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2755 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2756
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2757 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2758 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2759 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2760 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2761 g:result ..= 'base'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2762 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2763 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2764
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2765 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2766 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2767 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2768 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2769 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2770
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2771 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2772 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2773 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2774
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2775 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2776 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2777 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2778 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2779 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2780 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2781
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2782 # method of interface returns a value
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2783 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2784 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2785 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2786 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2787 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2788
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2789 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2790 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2791 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2792 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2793 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2794 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2795
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2796 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2797 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2798 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2799 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2800
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2801 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2802 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2803 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2804 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2805 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2806 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2807
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2808 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2809 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2810 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2811 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2812 return null_string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2813 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2814 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2815
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2816 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2817 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2818 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2819 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2820 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2821 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2822
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2823 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2824 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2825 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2826 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2827
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2828 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2829 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2830 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2831 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2832 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2833 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2834
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2835 # No class that implements the interface.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2836 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2837 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2838
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2839 interface IWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2840 def Enter(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2841 def Exit(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2842 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2843
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2844 def With1(ee: IWithEE, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2845 var r = ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2846 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2847
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2848 defcompile
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2849 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2850 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2851 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2852
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2853 def Test_class_used_as_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2854 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2855 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2856
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2857 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2858 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2859 var y = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2860 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2861
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2862 var p: Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2863 p = Point.new(2, 33)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2864 assert_equal(2, p.x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2865 assert_equal(33, p.y)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2866 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2867 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2868
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2869 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2870 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2871
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2872 interface HasX
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2873 var x: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2874 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2875
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2876 class Point implements HasX
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2877 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2878 var y = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2879 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2880
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2881 var p: Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2882 p = Point.new(2, 33)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2883 var hx = p
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2884 assert_equal(2, hx.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2885 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2886 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2887
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2888 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2889 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2890
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2891 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2892 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2893 var y = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2894 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2895
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2896 var p: Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2897 p = 'text'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2898 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2899 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected object<Point> but got string', 9)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2900 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2901
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2902 def Test_class_extends()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2903 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2904 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2905 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2906 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2907 def GetOne(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2908 return this.one
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2909 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2910 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2911 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2912 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2913 def GetTotal(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2914 return this.one + this.two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2915 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2916 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2917 var o = Child.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2918 assert_equal(1, o.one)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2919 assert_equal(2, o.two)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2920 assert_equal(1, o.GetOne())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2921 assert_equal(3, o.GetTotal())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2922 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2923 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2924
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2925 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2926 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2927 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2928 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2929 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2930 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2931 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2932 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2933 var o = Child.new(3, 44)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2934 assert_equal(3, o.one)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2935 assert_equal(44, o.two)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2936 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2937 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2938
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2939 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2940 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2941 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2942 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2943 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2944 class Child extends Base extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2945 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2946 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2947 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2948 v9.CheckSourceFailure(lines, 'E1352: Duplicate "extends"', 5)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2949
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2950 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2951 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2952 class Child extends BaseClass
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2953 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2954 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2955 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2956 v9.CheckSourceFailure(lines, 'E1353: Class name not found: BaseClass', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2957
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2958 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2959 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2960 var SomeVar = 99
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2961 class Child extends SomeVar
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2962 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2963 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2964 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2965 v9.CheckSourceFailure(lines, 'E1354: Cannot extend SomeVar', 5)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2966
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2967 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2968 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2969 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2970 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2971 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2972 return this.name
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2973 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2974 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2975
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2976 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2977 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2978 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2979 return super.ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2980 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2981 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2982
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2983 var o = Child.new('John', 42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2984 assert_equal('John: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2985 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2986 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2987
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2988 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2989 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2990 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2991 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2992 def ToString(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2993 return this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2994 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2995 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2996 return this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2997 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2998 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2999 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3000 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: ToString', 9)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3001
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3002 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3003 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3004 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3005 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3006 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3007 return super .ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3008 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3009 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3010 var o = Child.new(42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3011 echo o.ToString()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3012 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3013 v9.CheckSourceFailure(lines, 'E1356: "super" must be followed by a dot', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3014
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3015 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3016 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3017 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3018 var name: string
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3019 def ToString(): string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3020 return this.name
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3021 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3022 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3023
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3024 var age = 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3025 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3026 return super.ToString() .. ': ' .. age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3027 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3028 echo ToString()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3029 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3030 v9.CheckSourceFailure(lines, 'E1357: Using "super" not in a class method', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3031
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3032 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3033 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3034 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3035 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3036 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3037 return super.ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3038 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3039 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3040 var o = Child.new(42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3041 echo o.ToString()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3042 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3043 v9.CheckSourceFailure(lines, 'E1358: Using "super" not in a child class', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3044
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3045 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3046 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3047 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3048 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3049 static def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3050 return 'Base class'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3051 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3052 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3053
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3054 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3055 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3056 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3057 return Base.ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3058 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3059 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3060
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3061 var o = Child.new('John', 42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3062 assert_equal('Base class: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3063 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3064 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3065
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3066 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3067 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3068 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3069 var value = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3070 def new(init: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3071 this.value = number + 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3072 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3073 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3074 class Child extends Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3075 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3076 this.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3077 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3078 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3079 var c = Child.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3080 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3081 v9.CheckSourceFailure(lines, 'E1385: Class method "new" accessible only using class "Child"', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3082
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3083 # base class with more than one object member
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3084 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3085 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3086
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3087 class Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3088 var success: bool
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3089 var value: any = null
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3090 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3091
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3092 class Success extends Result
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3093 def new(this.value = v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3094 this.success = true
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3095 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3096 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3097
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3098 var v = Success.new('asdf')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3099 assert_equal("object of Success {success: true, value: 'asdf'}", string(v))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3100 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3101 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3102
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3103 # class name after "extends" doesn't end in a space or NUL character
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3104 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3105 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3106 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3107 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3108 class B extends A"
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3109 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3110 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3111 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A"', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3112 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3113
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3114 def Test_using_base_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3115 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3116 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3117
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3118 class BaseEE
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3119 def Enter(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3120 return null
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3121 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3122 def Exit(resource: any): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3123 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3124 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3125
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3126 class ChildEE extends BaseEE
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3127 def Enter(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3128 return 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3129 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3130
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3131 def Exit(resource: number): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3132 g:result ..= '/exit'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3133 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3134 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3135
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3136 def With(ee: BaseEE)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3137 var r = ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3138 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3139 g:result ..= r
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3140 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3141 g:result ..= '/finally'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3142 ee.Exit(r)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3143 endtry
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3144 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3145
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3146 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3147 With(ChildEE.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3148 assert_equal('42/finally/exit', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3149 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3150 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3151 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3152
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3153 # Using super, Child invokes Base method which has optional arg. #12471
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3154 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3155 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3156
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3157 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3158 var success: bool = false
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3159 def Method(arg = 0)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3160 this.success = true
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3161 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3162 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3163
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3164 class Child extends Base
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3165 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3166 super.Method()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3167 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3168 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3169
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3170 var obj = Child.new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3171 assert_equal(true, obj.success)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3172 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3173 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3174 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3175
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3176 def Test_class_import()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3177 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3178 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3179 export class Animal
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3180 var kind: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3181 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3182 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3183 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3184 writefile(lines, 'Xanimal.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3185
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3186 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3187 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3188 import './Xanimal.vim' as animal
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3189
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3190 var a: animal.Animal
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3191 a = animal.Animal.new('fish', 'Eric')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3192 assert_equal('fish', a.kind)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3193 assert_equal('Eric', a.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3194
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3195 var b: animal.Animal = animal.Animal.new('cat', 'Garfield')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3196 assert_equal('cat', b.kind)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3197 assert_equal('Garfield', b.name)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3198 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3199 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3200 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3201
34759
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3202 " Test for importing a class into a legacy script and calling the class method
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3203 def Test_class_method_from_legacy_script()
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3204 var lines =<< trim END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3205 vim9script
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3206 export class A
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3207 static var name: string = 'a'
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3208 static def SetName(n: string)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3209 name = n
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3210 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3211 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3212 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3213 writefile(lines, 'Xvim9export.vim', 'D')
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3214
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3215 lines =<< trim END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3216 import './Xvim9export.vim' as vim9
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3217
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3218 call s:vim9.A.SetName('b')
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3219 call assert_equal('b', s:vim9.A.name)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3220 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3221 v9.CheckScriptSuccess(lines)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3222 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3223
33929
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3224 " Test for implementing an imported interface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3225 def Test_implement_imported_interface()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3226 var lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3227 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3228 export interface Imp_Intf1
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3229 def Fn1(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3230 endinterface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3231 export interface Imp_Intf2
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3232 def Fn2(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3233 endinterface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3234 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3235 writefile(lines, 'Ximportinterface.vim', 'D')
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3236
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3237 lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3238 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3239 import './Ximportinterface.vim' as Xintf
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3240
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3241 class A implements Xintf.Imp_Intf1, Xintf.Imp_Intf2
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3242 def Fn1(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3243 return 10
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3244 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3245 def Fn2(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3246 return 20
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3247 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3248 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3249 var a = A.new()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3250 assert_equal(10, a.Fn1())
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3251 assert_equal(20, a.Fn2())
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3252 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3253 v9.CheckScriptSuccess(lines)
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3254 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3255
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3256 " Test for extending an imported class
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3257 def Test_extend_imported_class()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3258 var lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3259 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3260 export class Imp_C1
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3261 def Fn1(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3262 return 5
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3263 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3264 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3265 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3266 writefile(lines, 'Xextendimportclass.vim', 'D')
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3267
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3268 lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3269 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3270 import './Xextendimportclass.vim' as XClass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3271
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3272 class A extends XClass.Imp_C1
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3273 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3274 var a = A.new()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3275 assert_equal(5, a.Fn1())
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3276 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3277 v9.CheckScriptSuccess(lines)
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3278 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3279
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3280 def Test_abstract_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3281 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3282 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3283 abstract class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3284 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3285 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3286 class Person extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3287 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3288 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3289 var p: Base = Person.new('Peter', 42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3290 assert_equal('Peter', p.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3291 assert_equal(42, p.age)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3292 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3293 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3294
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3295 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3296 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3297 abstract class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3298 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3299 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3300 class Person extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3301 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3302 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3303 var p = Base.new('Peter')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3304 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
3305 v9.CheckSourceFailure(lines, 'E1325: Method "new" not found in class "Base"', 8)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3306
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3307 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3308 abstract class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3309 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3310 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3311 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3312 v9.CheckSourceFailure(lines, 'E1316: Class can only be defined in Vim9 script', 1)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3313
35062
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3314 # Additional commands after "abstract class"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3315 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3316 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3317 abstract class Something | var x = []
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3318 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3319 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3320 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = []", 2)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3321
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3322 # Abstract class cannot have a "new" function
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3323 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3324 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3325 abstract class Base
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3326 def new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3327 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3328 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3329 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3330 v9.CheckSourceFailure(lines, 'E1359: Cannot define a "new" method in an abstract class', 4)
34759
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3331
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3332 # extending an abstract class with class methods and variables
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3333 lines =<< trim END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3334 vim9script
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3335 abstract class A
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3336 static var s: string = 'vim'
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3337 static def Fn(): list<number>
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3338 return [10]
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3339 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3340 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3341 class B extends A
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3342 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3343 var b = B.new()
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3344 assert_equal('vim', A.s)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3345 assert_equal([10], A.Fn())
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3346 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3347 v9.CheckScriptSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3348 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3349
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3350 def Test_closure_in_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3351 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3352 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3353
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3354 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3355 var y: list<string> = ['B']
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3356
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3357 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3358 g:result = filter(['A', 'B'], (_, v) => index(this.y, v) == -1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3359 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3360 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3361
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3362 Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3363 assert_equal(['A'], g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3364 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3365 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3366 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3367
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3368 def Test_construct_object_from_legacy()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3369 # Cannot directly invoke constructor from legacy
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3370 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3371 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3372
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3373 var newCalled = false
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3374
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3375 class A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3376 def new(arg: string)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3377 newCalled = true
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3378 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3379 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3380
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3381 export def CreateA(...args: list<any>): A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3382 return call(A.new, args)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3383 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3384
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3385 g:P = CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3386 legacy call g:P('some_arg')
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3387 assert_equal(true, newCalled)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3388 unlet g:P
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3389 END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3390 v9.CheckSourceSuccess(lines)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3391
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3392 lines =<< trim END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3393 vim9script
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3394
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3395 var newCalled = false
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3396
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3397 class A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3398 static def CreateA(options = {}): any
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3399 return A.new()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3400 enddef
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3401 def new()
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3402 newCalled = true
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3403 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3404 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3405
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3406 g:P = A.CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3407 legacy call g:P()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3408 assert_equal(true, newCalled)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3409 unlet g:P
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3410 END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3411 v9.CheckSourceSuccess(lines)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3412
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3413 # This also tests invoking "new()" with "call"
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3414 lines =<< trim END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3415 vim9script
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3416
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3417 var createdObject: any
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3418
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3419 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3420 var val1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3421 var val2: number
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3422 static def CreateA(...args: list<any>): any
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3423 createdObject = call(A.new, args)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3424 return createdObject
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3425 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3426 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3427
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3428 g:P = A.CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3429 legacy call g:P(3, 5)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3430 assert_equal(3, createdObject.val1)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3431 assert_equal(5, createdObject.val2)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3432 legacy call g:P()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3433 assert_equal(0, createdObject.val1)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3434 assert_equal(0, createdObject.val2)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3435 legacy call g:P(7)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3436 assert_equal(7, createdObject.val1)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3437 assert_equal(0, createdObject.val2)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3438 unlet g:P
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3439 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3440 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3441 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3442
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3443 def Test_defer_with_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3444 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3445 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3446
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3447 class CWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3448 def Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3449 g:result ..= "entered/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3450 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3451 def Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3452 g:result ..= "exited"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3453 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3454 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3455
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3456 def With(ee: CWithEE, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3457 ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3458 defer ee.Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3459 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3460 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3461
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3462 g:result = ''
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3463 var obj = CWithEE.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3464 obj->With(() => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3465 g:result ..= "called/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3466 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3467 assert_equal('entered/called/exited', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3468 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3469 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3470 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3471
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3472 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3473 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3474
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3475 class BaseWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3476 def Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3477 g:result ..= "entered-base/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3478 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3479 def Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3480 g:result ..= "exited-base"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3481 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3482 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3483
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3484 class CWithEE extends BaseWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3485 def Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3486 g:result ..= "entered-child/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3487 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3488 def Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3489 g:result ..= "exited-child"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3490 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3491 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3492
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3493 def With(ee: BaseWithEE, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3494 ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3495 defer ee.Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3496 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3497 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3498
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3499 g:result = ''
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3500 var obj = CWithEE.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3501 obj->With(() => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3502 g:result ..= "called/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3503 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3504 assert_equal('entered-child/called/exited-child', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3505 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3506 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3507 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3508 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3509
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3510 " The following test used to crash Vim (Github issue #12676)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3511 def Test_extends_method_crashes_vim()
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3512 var lines =<< trim END
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3513 vim9script
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3514
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3515 class Observer
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3516 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3517
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3518 class Property
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3519 var value: any
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3520
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3521 def Set(v: any)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3522 if v != this.value
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3523 this.value = v
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3524 endif
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3525 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3526
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3527 def Register(observer: Observer)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3528 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3529 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3530
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3531 class Bool extends Property
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3532 var value2: bool
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3533 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3534
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3535 def Observe(obj: Property, who: Observer)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3536 obj.Register(who)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3537 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3538
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3539 var p = Bool.new(false)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3540 var myObserver = Observer.new()
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3541
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3542 Observe(p, myObserver)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3543
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3544 p.Set(true)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3545 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3546 v9.CheckSourceSuccess(lines)
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3547 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3548
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3549 " Test for calling a method in a class that is extended
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3550 def Test_call_method_in_extended_class()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3551 var lines =<< trim END
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3552 vim9script
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3553
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3554 var prop_init_called = false
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3555 var prop_register_called = false
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3556
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3557 class Property
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3558 def Init()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3559 prop_init_called = true
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3560 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3561
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3562 def Register()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3563 prop_register_called = true
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3564 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3565 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3566
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3567 class Bool extends Property
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3568 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3569
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3570 def Observe(obj: Property)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3571 obj.Register()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3572 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3573
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3574 var p = Property.new()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3575 Observe(p)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3576
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3577 p.Init()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3578 assert_true(prop_init_called)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3579 assert_true(prop_register_called)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3580 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3581 v9.CheckSourceSuccess(lines)
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3582 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3583
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3584 def Test_instanceof()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3585 var lines =<< trim END
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3586 vim9script
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3587
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3588 class Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3589 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3590
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3591 class Base2 extends Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3592 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3593
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3594 interface Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3595 endinterface
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3596
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3597 class Mix1 implements Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3598 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3599
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3600 class Base3 extends Mix1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3601 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3602
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3603 type AliasBase1 = Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3604 type AliasBase2 = Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3605 type AliasIntf1 = Intf1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3606 type AliasMix1 = Mix1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3607
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3608 var b1 = Base1.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3609 var b2 = Base2.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3610 var b3 = Base3.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3611
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3612 assert_true(instanceof(b1, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3613 assert_true(instanceof(b2, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3614 assert_false(instanceof(b1, Base2))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3615 assert_true(instanceof(b3, Mix1))
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3616 assert_true(instanceof(b3, Base1, Base2, Intf1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3617
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3618 assert_true(instanceof(b1, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3619 assert_true(instanceof(b2, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3620 assert_false(instanceof(b1, AliasBase2))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3621 assert_true(instanceof(b3, AliasMix1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3622 assert_true(instanceof(b3, AliasBase1, AliasBase2, AliasIntf1))
33019
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3623
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3624 def Foo()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3625 var a1 = Base1.new()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3626 var a2 = Base2.new()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3627 var a3 = Base3.new()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3628
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3629 assert_true(instanceof(a1, Base1))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3630 assert_true(instanceof(a2, Base1))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3631 assert_false(instanceof(a1, Base2))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3632 assert_true(instanceof(a3, Mix1))
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3633 assert_true(instanceof(a3, Base1, Base2, Intf1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3634
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3635 assert_true(instanceof(a1, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3636 assert_true(instanceof(a2, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3637 assert_false(instanceof(a1, AliasBase2))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3638 assert_true(instanceof(a3, AliasMix1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3639 assert_true(instanceof(a3, AliasBase1, AliasBase2, AliasIntf1))
33019
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3640 enddef
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3641 Foo()
33291
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3642
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3643 var o_null: Base1
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3644 assert_false(instanceof(o_null, Base1))
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3645
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3646 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3647 v9.CheckSourceSuccess(lines)
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3648
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3649 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3650 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3651
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3652 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3653 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3654 instanceof(Base1.new())
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3655 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3656 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: instanceof')
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3657
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3658 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3659 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3660
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3661 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3662 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3663 def F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3664 instanceof(Base1.new())
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3665 enddef
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3666 F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3667 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3668 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: instanceof')
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3669
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3670 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3671 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3672
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3673 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3674 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3675
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3676 class Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3677 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3678
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3679 var o = Base2.new()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3680 instanceof(o, Base1, Base2, 3)
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3681 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3682 v9.CheckSourceFailure(lines, 'E693: Class or class typealias required for argument 4', 10)
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3683
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3684 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3685 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3686
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3687 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3688 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3689
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3690 class Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3691 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3692
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3693 def F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3694 var o = Base2.new()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3695 instanceof(o, Base1, Base2, 3)
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3696 enddef
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3697 F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3698 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3699 v9.CheckSourceFailure(lines, 'E693: Class or class typealias required for argument 4')
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3700 enddef
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3701
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3702 " Test for calling a method in the parent class that is extended partially.
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3703 " This used to fail with the 'E118: Too many arguments for function: Text' error
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3704 " message (Github issue #12524).
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3705 def Test_call_method_in_parent_class()
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3706 var lines =<< trim END
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3707 vim9script
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3708
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3709 class Widget
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3710 var _lnum: number = 1
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3711
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3712 def SetY(lnum: number)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3713 this._lnum = lnum
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3714 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3715
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3716 def Text(): string
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3717 return ''
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3718 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3719 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3720
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3721 class Foo extends Widget
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3722 def Text(): string
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3723 return '<Foo>'
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3724 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3725 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3726
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3727 def Stack(w1: Widget, w2: Widget): list<Widget>
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3728 w1.SetY(1)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3729 w2.SetY(2)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3730 return [w1, w2]
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3731 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3732
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3733 var foo1 = Foo.new()
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3734 var foo2 = Foo.new()
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3735 var l = Stack(foo1, foo2)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3736 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3737 v9.CheckSourceSuccess(lines)
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3738 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3739
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3740 " Test for calling methods from three levels of classes
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3741 def Test_multi_level_method_call()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3742 var lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3743 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3744
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3745 var A_func1: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3746 var A_func2: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3747 var A_func3: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3748 var B_func2: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3749 var B_func3: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3750 var C_func3: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3751
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3752 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3753 def Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3754 A_func1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3755 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3756
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3757 def Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3758 A_func2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3759 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3760
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3761 def Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3762 A_func3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3763 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3764 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3765
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3766 class B extends A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3767 def Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3768 B_func2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3769 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3770
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3771 def Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3772 B_func3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3773 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3774 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3775
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3776 class C extends B
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3777 def Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3778 C_func3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3779 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3780 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3781
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3782 def A_CallFuncs(a: A)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3783 a.Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3784 a.Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3785 a.Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3786 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3787
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3788 def B_CallFuncs(b: B)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3789 b.Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3790 b.Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3791 b.Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3792 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3793
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3794 def C_CallFuncs(c: C)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3795 c.Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3796 c.Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3797 c.Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3798 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3799
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3800 var cobj = C.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3801 A_CallFuncs(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3802 B_CallFuncs(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3803 C_CallFuncs(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3804 assert_equal(3, A_func1)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3805 assert_equal(0, A_func2)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3806 assert_equal(0, A_func3)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3807 assert_equal(3, B_func2)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3808 assert_equal(0, B_func3)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3809 assert_equal(3, C_func3)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3810 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3811 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3812 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3813
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3814 " Test for using members from three levels of classes
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3815 def Test_multi_level_member_access()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3816 var lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3817 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3818
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3819 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3820 public var val1: number = 0
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3821 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3822
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3823 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3824 public var val2: number = 0
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3825 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3826
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3827 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3828 public var val3: number = 0
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3829 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3830
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3831 def A_members(a: A)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3832 a.val1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3833 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3834
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3835 def B_members(b: B)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3836 b.val1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3837 b.val2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3838 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3839
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3840 def C_members(c: C)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3841 c.val1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3842 c.val2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3843 c.val3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3844 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3845
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3846 var cobj = C.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3847 A_members(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3848 B_members(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3849 C_members(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3850 assert_equal(3, cobj.val1)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
3851 assert_equal(2, cobj.val2)
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
3852 assert_equal(1, cobj.val3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3853 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3854 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3855 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3856
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3857 " Test expansion of <stack> with class methods.
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3858 def Test_stack_expansion_with_methods()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3859 var lines =<< trim END
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3860 vim9script
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3861
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3862 class C
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3863 def M1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3864 F0()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3865 enddef
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3866 endclass
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3867
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3868 def F0()
34755
1a411f737239 patch 9.1.0255: Vim9: no indication of script nr in stack trace of classes
Christian Brabandt <cb@256bit.org>
parents: 34748
diff changeset
3869 assert_match('<SNR>\d\+_F\[1\]\.\.<SNR>\d\+_C\.M1\[1\]\.\.<SNR>\d\+_F0\[1\]$', expand('<stack>'))
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3870 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3871
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3872 def F()
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3873 C.new().M1()
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3874 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3875
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3876 F()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3877 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3878 v9.CheckSourceSuccess(lines)
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3879 enddef
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3880
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3881 " Test the return type of the new() constructor
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3882 def Test_new_return_type()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3883 # new() uses the default return type and there is no return statement
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3884 var lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3885 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3886
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3887 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3888 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3889
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3890 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3891 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3892 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3893 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3894 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3895 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3896
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3897 var c = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3898 assert_equal('object<C>', typename(c))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3899
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3900 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3901 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3902 assert_equal('object<C>', typename(v1))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3904 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3905 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3906 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3907 assert_equal('object<C>', typename(v2))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3908 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3909 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3910 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3911 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3912
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3913 # new() uses the default return type and an empty 'return' statement
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3914 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3915 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3916
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3917 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3918 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3919
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3920 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3921 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3922 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3923 return
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3924 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3925 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3926 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3927
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3928 var c = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3929 assert_equal('object<C>', typename(c))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3930
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3931 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3932 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3933 assert_equal('object<C>', typename(v1))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3934
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3935 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3936 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3937 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3938 assert_equal('object<C>', typename(v2))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3939 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3940 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3941 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3942 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3943
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3944 # new() uses "any" return type and returns "this"
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3945 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3946 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3947
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3948 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3949 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3950
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3951 def new(this._bufnr): any
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3952 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3953 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3954 return this
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3955 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3956 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3957 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3958 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3959 v9.CheckSourceFailure(lines, 'E1365: Cannot use a return type with the "new" method', 11)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3960
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3961 # new() uses 'Dict' return type and returns a Dict
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3962 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3963 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3964
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3965 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3966 var _state: dict<any>
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3967
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3968 def new(): dict<any>
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3969 this._state = {}
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3970 return this._state
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3971 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3972 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3973
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3974 var c = C.new()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3975 assert_equal('object<C>', typename(c))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3976 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3977 v9.CheckSourceFailure(lines, 'E1365: Cannot use a return type with the "new" method', 9)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3978 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3979
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3980 " Test for checking a member initialization type at run time.
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3981 def Test_runtime_type_check_for_member_init()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3982 var lines =<< trim END
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3983 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3984
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3985 var retnum: bool = false
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3986
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3987 def F(): any
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3988 retnum = !retnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3989 if retnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3990 return 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3991 else
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3992 return "hello"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3993 endif
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3994 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3995
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3996 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3997 var _foo: bool = F()
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3998 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3999
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4000 var c1 = C.new()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4001 var c2 = C.new()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4002 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4003 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected bool but got string', 0)
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4004 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4005
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4006 " Test for locking a variable referring to an object and reassigning to another
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4007 " object.
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4008 def Test_lockvar_object()
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4009 var lines =<< trim END
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4010 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4011
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4012 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4013 var val: number
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4014 def new(this.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4015 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4016 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4017
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4018 var some_dict: dict<C> = { a: C.new(1), b: C.new(2), c: C.new(3), }
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4019 lockvar 2 some_dict
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4020
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4021 var current: C
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4022 current = some_dict['c']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4023 assert_equal(3, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4024 current = some_dict['b']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4025 assert_equal(2, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4026
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4027 def F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4028 current = some_dict['c']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4029 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4030
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4031 def G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4032 current = some_dict['b']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4033 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4034
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4035 F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4036 assert_equal(3, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4037 G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4038 assert_equal(2, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4039 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4040 v9.CheckSourceSuccess(lines)
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4041 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4042
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4043 " Test trying to lock an object variable from various places
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4044 def Test_lockvar_object_variable()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4045 # An object variable lockvar has several cases:
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4046 # object method, scriptlevel, scriplevel from :def, :def arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4047 # method arg, static method arg.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4048 # Also different depths
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4049
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4050 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4051 # lockvar of read-only object variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4052 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4053
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4054 # read-only lockvar from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4055 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4056 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4057
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4058 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4059 var val1: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4060 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4061 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4062 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4063 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4064 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4065 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4066 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4067 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "this.val1" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4068
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4069 # read-only lockvar from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4070 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4071 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4072
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4073 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4074 var val2: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4075 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4076 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4077 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4078 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4079 v9.CheckSourceFailure(lines, 'E1335: Variable "val2" in class "C" is not writable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4080
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4081 # read-only lockvar of scriptlevel variable from def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4082 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4083 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4084
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4085 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4086 var val3: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4087 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4088 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4089 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4090 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4091 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4092 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4093 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4094 v9.CheckSourceFailure(lines, 'E1335: Variable "val3" in class "C" is not writable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4095
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4096 # read-only lockvar of def argument variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4097 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4098 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4099
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4100 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4101 var val4: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4102 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4103 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4104 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4105 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4106 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4107 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4108 v9.CheckSourceFailure(lines, 'E1335: Variable "val4" in class "C" is not writable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4109
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4110 # TODO: the following tests use type "any" for argument. Need a run time
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4111 # check for access. Probably OK as is for now.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4112
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4113 # read-only lockvar from object method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4114 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4115 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4116
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4117 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4118 var val5: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4119 def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4120 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4121 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4122 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4123 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4124 o.Lock(C.new(5))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4125 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4126 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4127
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4128 # read-only lockvar from class method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4129 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4130 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4131
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4132 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4133 var val6: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4134 static def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4135 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4136 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4137 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4138 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4139 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4140 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4141 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4142
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4143 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4144 # lockvar of public object variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4145 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4146
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4147 # lockvar from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4148 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4149 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4150
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4151 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4152 public var val1: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4153 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4154 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4155 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4156 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4157 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4158 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4159 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4160 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "this.val1" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4161
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4162 # lockvar from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4163 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4164 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4165
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4166 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4167 public var val2: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4168 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4169 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4170 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4171 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4172 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o.val2" in class "C"', 7)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4173
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4174 # lockvar of scriptlevel variable from def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4175 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4176 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4177
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4178 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4179 public var val3: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4180 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4181 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4182 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4183 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4184 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4185 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4186 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4187 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o.val3" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4188
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4189 # lockvar of def argument variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4190 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4191 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4192
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4193 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4194 public var val4: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4195 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4196 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4197 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4198 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4199 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4200 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4201 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o.val4" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4202
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4203 # lockvar from object method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4204 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4205 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4206
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4207 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4208 public var val5: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4209 def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4210 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4211 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4212 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4213 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4214 o.Lock(C.new(5))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4215 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4216 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4217
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4218 # lockvar from class method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4219 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4220 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4221
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4222 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4223 public var val6: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4224 static def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4225 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4226 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4227 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4228 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4229 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4230 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4231 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4232 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4233
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4234 " Test trying to lock a class variable from various places
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4235 def Test_lockvar_class_variable()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4236
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4237 # lockvar bare static from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4238 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4239 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4240
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4241 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4242 public static var sval1: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4243 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4244 lockvar sval1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4245 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4246 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4247 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4248 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4249 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4250 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "sval1" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4251
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4252 # lockvar C.static from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4253 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4254 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4255
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4256 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4257 public static var sval2: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4258 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4259 lockvar C.sval2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4260 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4261 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4262 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4263 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4264 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4265 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "C.sval2" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4266
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4267 # lockvar bare static from class method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4268 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4269 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4270
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4271 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4272 public static var sval3: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4273 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4274 lockvar sval3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4275 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4276 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4277 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4278 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4279 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "sval3" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4280
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4281 # lockvar C.static from class method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4282 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4283 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4284
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4285 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4286 public static var sval4: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4287 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4288 lockvar C.sval4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4289 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4290 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4291 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4292 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4293 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "C.sval4" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4294
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4295 # lockvar C.static from script level
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4296 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4297 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4298
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4299 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4300 public static var sval5: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4301 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4302 lockvar C.sval5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4303 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4304 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "C.sval5" in class "C"', 6)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4305
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4306 # lockvar o.static from script level
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4307 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4308 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4309
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4310 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4311 public static var sval6: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4312 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4313 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4314 lockvar o.sval6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4315 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4316 v9.CheckSourceFailure(lines, 'E1375: Class variable "sval6" accessible only using class "C"', 7)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4317 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4318
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4319 " Test locking an argument to :def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4320 def Test_lockvar_argument()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4321 # Lockvar a function arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4322 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4323 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4324
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4325 def Lock(val: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4326 lockvar val
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4327 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4328
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4329 var d = {a: 1, b: 2}
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4330 Lock(d)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4331
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4332 d->extend({c: 3})
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4333 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4334 v9.CheckSourceFailure(lines, 'E741: Value is locked: extend() argument')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4335
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4336 # Lockvar a function arg. Verify "sval" is interpreted as argument and not a
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4337 # class member in "C". This tests lval_root_is_arg.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4338 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4339 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4340
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4341 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4342 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4343 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4344
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4345 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4346 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4347 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4348
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4349 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4350 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4351 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4352 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4353
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4354 # Lock a class.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4355 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4356 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4357
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4358 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4359 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4360 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4361
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4362 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4363 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4364 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4365
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4366 Lock2(C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4367 END
33936
bdd408288d95 patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents: 33933
diff changeset
4368 v9.CheckSourceFailure(lines, 'E1405: Class "C" cannot be used as a value')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4369
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4370 # Lock an object.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4371 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4372 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4373
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4374 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4375 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4376 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4377
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4378 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4379 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4380 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4381
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4382 Lock2(C.new())
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4383 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4384 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4385
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4386 # In this case (unlike previous) "lockvar sval" is a class member.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4387 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4388 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4389
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4390 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4391 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4392 def Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4393 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4394 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4395 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4396
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4397
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4398 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4399 o.Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4400 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4401 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "sval" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4402 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4403
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4404 " Test that this can be locked without error
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4405 def Test_lockvar_this()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4406 # lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4407 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4408 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4409 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4410 def TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4411 lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4412 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4413 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4414 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4415 o.TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4416 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4417 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4418
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4419 # lockvar four (four letter word, but not this)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4420 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4421 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4422 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4423 def TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4424 var four: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4425 lockvar four
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4426 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4427 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4428 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4429 o.TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4430 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4431 v9.CheckSourceFailure(lines, 'E1178: Cannot lock or unlock a local variable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4432
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4433 # lockvar this5; "this" + one char, 5 letter word, starting with "this"
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4434 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4435 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4436 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4437 def TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4438 var this5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4439 lockvar this5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4440 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4441 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4442 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4443 o.TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4444 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4445 v9.CheckSourceFailure(lines, 'E1178: Cannot lock or unlock a local variable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4446 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4447
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4448 " Test some general lockvar cases
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4449 def Test_lockvar_general()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4450 # lockvar an object and a class. It does nothing
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4451 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4452 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4453 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4454 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4455 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4456 lockvar o
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4457 lockvar C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4458 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4459 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4460
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4461 # Lock a list element that's nested in an object variable from a :def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4462 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4463 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4464
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4465 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4466 public var val: list<list<number>> = [ [1], [2], [3] ]
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4467 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4468 def Lock2(obj: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4469 lockvar obj.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4470 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4471
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4472 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4473 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4474 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4475 assert_equal([ [9], [2], [3] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4476 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4477 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4478 call assert_false(true, 'assign should have failed')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4479 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4480 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4481 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4482 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4483 assert_equal([ [9], [2], [8] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4484 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4485 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4486
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4487 # Lock a list element that's nested in an object variable from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4488 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4489 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4490
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4491 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4492 public var val: list<list<number>> = [ [1], [2], [3] ]
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4493 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4494
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4495 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4496 lockvar o.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4497 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4498 assert_equal([ [9], [2], [3] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4499 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4500 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4501 call assert_false(true, 'assign should have failed')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4502 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4503 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4504 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4505 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4506 assert_equal([ [9], [2], [8] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4507 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4508 v9.CheckSourceSuccess(lines)
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4509
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4510 # lock a script level variable from an object method
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4511 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4512 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4513
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4514 class C
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4515 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4516 lockvar l
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4517 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4518 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4519
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4520 var l = [1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4521 C.new().Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4522 l[0] = 11
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4523 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4524 v9.CheckSourceFailure(lines, 'E741: Value is locked: l[0] = 11', 11)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4525
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4526 # lock a list element referenced by a protected object variable
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4527 # in an object fetched via a script level list
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4528 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4529 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4530
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4531 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4532 var _v1: list<list<number>>
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4533 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4534 lockvar lc[0]._v1[1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4535 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4536 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4537
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4538 var l = [[1], [2], [3]]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4539 var o = C.new(l)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4540 var lc: list<C> = [ o ]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4541
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4542 o.Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4543 l[0] = [22]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4544 l[1] = [33]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4545 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4546 v9.CheckSourceFailure(lines, 'E741: Value is locked: l[1] = [33]', 16)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4547
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4548 # similar to the previous test, except the locking code is executing
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4549 # in a class that does not own the protected variable.
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4550 # Note that the locking code is in a class has a protected variable of
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4551 # the same name.
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4552 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4553 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4554
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4555 class C2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4556 var _v1: list<list<number>>
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4557 def Lock(obj: any)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4558 lockvar lc[0]._v1[1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4559 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4560 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4561
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4562 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4563 var _v1: list<list<number>>
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4564 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4565
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4566 var l = [[1], [2], [3]]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4567 var o = C.new(l)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4568 var lc: list<C> = [ o ]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4569
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4570 var o2 = C2.new()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4571 o2.Lock(o)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4572 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4573 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4574 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4575
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4576 " Test builtin islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4577 def Test_lockvar_islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4578 # Can't lock class/object variable
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4579 # Lock class/object variable's value
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
4580 # Lock item of variable's value (a list item)
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
4581 # variable is at index 1 within class/object
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4582 var lines =<< trim END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4583 vim9script
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4584
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4585 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4586 var o0: list<list<number>> = [ [0], [1], [2]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4587 var o1: list<list<number>> = [[10], [11], [12]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4588 static var c0: list<list<number>> = [[20], [21], [22]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4589 static var c1: list<list<number>> = [[30], [31], [32]]
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4590 endclass
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4591
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4592 def LockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4593 lockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4594 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4595
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4596 def UnlockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4597 unlockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4598 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4599
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4600 var obj = C.new()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4601 #lockvar obj.o1 # can't lock something you can't write to
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4602
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4603 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4604 lockvar obj.o1 # can't lock something you can't write to
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4605 call assert_false(1, '"lockvar obj.o1" should have failed')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4606 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4607 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4608 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4609
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4610 LockIt(obj.o1) # but can lock it's value
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4611 assert_equal(1, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4612 assert_equal(1, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4613 assert_equal(1, islocked("obj.o1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4614 UnlockIt(obj.o1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4615 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4616 assert_equal(0, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4617
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4618 lockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4619 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4620 assert_equal(1, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4621 assert_equal(0, islocked("obj.o1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4622 unlockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4623 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4624 assert_equal(0, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4625
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4626 # Same thing, but with a static
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4627
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4628 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4629 lockvar C.c1 # can't lock something you can't write to
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4630 call assert_false(1, '"lockvar C.c1" should have failed')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4631 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4632 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4633 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4634
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4635 LockIt(C.c1) # but can lock it's value
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4636 assert_equal(1, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4637 assert_equal(1, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4638 assert_equal(1, islocked("C.c1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4639 UnlockIt(C.c1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4640 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4641 assert_equal(0, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4642
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4643 lockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4644 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4645 assert_equal(1, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4646 assert_equal(0, islocked("C.c1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4647 unlockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4648 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4649 assert_equal(0, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4650 END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4651 v9.CheckSourceSuccess(lines)
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4652
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4653 # Do islocked() from an object method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4654 # and then from a class method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4655 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4656 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4657
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4658 var l0o0 = [ [0], [1], [2]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4659 var l0o1 = [ [10], [11], [12]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4660 var l0c0 = [[120], [121], [122]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4661 var l0c1 = [[130], [131], [132]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4662
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4663 class C0
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4664 var o0: list<list<number>> = l0o0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4665 var o1: list<list<number>> = l0o1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4666 static var c0: list<list<number>> = l0c0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4667 static var c1: list<list<number>> = l0c1
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4668 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4669 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4670 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4671 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4672 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4673 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4674 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4675
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4676 var l2o0 = [[20000], [20001], [20002]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4677 var l2o1 = [[20010], [20011], [20012]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4678 var l2c0 = [[20120], [20121], [20122]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4679 var l2c1 = [[20130], [20131], [20132]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4680
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4681 class C2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4682 var o0: list<list<number>> = l2o0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4683 var o1: list<list<number>> = l2o1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4684 static var c0: list<list<number>> = l2c0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4685 static var c1: list<list<number>> = l2c1
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4686 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4687 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4688 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4689 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4690 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4691 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4692 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4693
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4694 var obj0 = C0.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4695 var obj2 = C2.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4696
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4697 var l = [ obj0, null_object, obj2 ]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4698
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4699 # lock list, object func access through script var expr
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4700 assert_equal(0, obj0.Islocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4701 assert_equal(0, obj0.Islocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4702 lockvar l0o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4703 assert_equal(1, obj0.Islocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4704 assert_equal(1, obj0.Islocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4705
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4706 #echo "check-b" obj2.Islocked("l[1].o1") # NULL OBJECT
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4707
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4708 # lock list element, object func access through script var expr
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4709 lockvar l0o1[1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4710 assert_equal(0, obj0.Islocked("this.o1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4711 assert_equal(1, obj0.Islocked("this.o1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4712
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4713 assert_equal(0, obj0.Islocked("this.o1"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4714 lockvar l0o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4715 assert_equal(1, obj0.Islocked("this.o1"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4716 unlockvar l0o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4717
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4718 lockvar l0c1[1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4719
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4720 # static by class name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4721 assert_equal(0, obj0.Islocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4722 assert_equal(1, obj0.Islocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4723 # static by bare name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4724 assert_equal(0, obj0.Islocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4725 assert_equal(1, obj0.Islocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4726
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4727 # static by class name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4728 assert_equal(0, obj2.Islocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4729 assert_equal(1, obj2.Islocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4730 # static by bare name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4731 assert_equal(0, obj2.Islocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4732 assert_equal(0, obj2.Islocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4733
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4734
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4735 # static by bare name in same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4736 assert_equal(0, obj0.Islocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4737 lockvar l0c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4738 assert_equal(1, obj0.Islocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4739
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4740 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4741 # similar stuff, but use static method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4742 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4743
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4744 unlockvar l0o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4745
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4746 # lock list, object func access through script var expr
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4747 assert_equal(0, C0.SIslocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4748 assert_equal(0, C0.SIslocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4749 lockvar l0o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4750 assert_equal(1, C0.SIslocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4751 assert_equal(1, C0.SIslocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4752
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4753 unlockvar l0o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4754
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4755 # can't access "this" from class method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4756 try
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4757 C0.SIslocked("this.o1[0]")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4758 call assert_0(1, '"C0.SIslocked("this.o1[0]")" should have failed')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4759 catch
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4760 call assert_exception('E121: Undefined variable: this')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4761 endtry
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4762
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4763 lockvar l0c1[1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4764
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4765 # static by class name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4766 assert_equal(0, C0.SIslocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4767 assert_equal(1, C0.SIslocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4768 # static by bare name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4769 assert_equal(0, C0.SIslocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4770 assert_equal(1, C0.SIslocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4771
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4772 # static by class name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4773 assert_equal(0, C2.SIslocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4774 assert_equal(1, C2.SIslocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4775 # static by bare name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4776 assert_equal(0, C2.SIslocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4777 assert_equal(0, C2.SIslocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4778
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4779
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4780 # static by bare name in same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4781 unlockvar l0c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4782 assert_equal(0, C0.SIslocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4783 lockvar l0c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4784 assert_equal(1, C0.SIslocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4785 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4786 v9.CheckSourceSuccess(lines)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4787
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4788 # Check islocked class/object from various places.
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4789 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4790 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4791
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4792 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4793 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4794 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4795 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4796 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4797 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4798 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4799 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4800 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4801
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4802 # object method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4803 assert_equal(0, obj.Islocked("this"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4804 assert_equal(0, obj.Islocked("C"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4805
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4806 # class method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4807 ### assert_equal(0, C.SIslocked("this"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4808 assert_equal(0, C.SIslocked("C"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4809
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4810 #script level
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4811 var v: number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4812 v = islocked("C")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4813 assert_equal(0, v)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4814 v = islocked("obj")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4815 assert_equal(0, v)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4816 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4817 v9.CheckSourceSuccess(lines)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4818 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4819
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4820 def Test_lockvar_islocked_notfound()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4821 # Try non-existent things
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4822 var lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4823 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4824
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4825 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4826 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4827 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4828 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4829 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4830 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4831 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4832 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4833 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4834 assert_equal(-1, obj.Islocked("anywhere"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4835 assert_equal(-1, C.SIslocked("notanywhere"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4836 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4837 v9.CheckSourceSuccess(lines)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4838
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4839 # Something not found of the form "name1.name2" is an error
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4840 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4841 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4842
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4843 islocked("one.two")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4844 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4845 v9.CheckSourceFailure(lines, 'E121: Undefined variable: one')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4846
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4847 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4848 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4849
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4850 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4851 var val = { key: "value" }
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4852 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4853 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4854 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4855 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4856 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4857 obj.Islocked("this.val.not_there"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4858 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4859 v9.CheckSourceFailure(lines, 'E716: Key not present in Dictionary: "not_there"')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4860
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4861 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4862 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4863
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4864 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4865 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4866 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4867 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4868 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4869 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4870 obj.Islocked("this.notobjmember")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4871 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
4872 v9.CheckSourceFailure(lines, 'E1326: Variable "notobjmember" not found in object "C"')
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4873
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4874 # access a script variable through methods
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4875 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4876 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4877
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4878 var l = [1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4879 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4880 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4881 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4882 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4883 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4884 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4885 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4886 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4887 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4888 assert_equal(0, obj.Islocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4889 assert_equal(0, C.SIslocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4890 lockvar l
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4891 assert_equal(1, obj.Islocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4892 assert_equal(1, C.SIslocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4893 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4894 v9.CheckSourceSuccess(lines)
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4895 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4896
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4897 " Test for a protected object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4898 def Test_private_object_method()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4899 # Try calling a protected method using an object (at the script level)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4900 var lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4901 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4902
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4903 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4904 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4905 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4906 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4907 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4908 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4909 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4910 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4911 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 9)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4912
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4913 # Try calling a protected method using an object (from a def function)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4914 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4915 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4916
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4917 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4918 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4919 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4920 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4921 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4922 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4923 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4924 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4925 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4926 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4927 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4928 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4929
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4930 # Use a protected method from another object method (in script context)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4931 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4932 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4933
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4934 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4935 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4936 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4937 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4938 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4939 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4940 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4941 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4942 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4943 assert_equal(1234, a.Bar())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4944 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4945 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4946
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4947 # Use a protected method from another object method (def function context)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4948 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4949 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4950
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4951 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4952 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4953 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4954 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4955 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4956 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4957 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4958 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4959 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4960 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4961 assert_equal(1234, a.Bar())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4962 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4963 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4964 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4965 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4966
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4967 # Try calling a protected method without the "this" prefix
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4968 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4969 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4970
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4971 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4972 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4973 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4974 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4975 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4976 return _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4977 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4978 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4979 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4980 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4981 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4982 v9.CheckSourceFailure(lines, 'E117: Unknown function: _Foo', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4983
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4984 # Try calling a protected method using the class name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4985 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4986 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4987
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4988 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4989 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4990 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4991 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4992 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4993 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4994 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4995 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 8)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4996
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4997 # Define two protected methods with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4998 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4999 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5000
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5001 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5002 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5003 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5004 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5005 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5006 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5007 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5008 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5009 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5010
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5011 # Define a protected method and a object method with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5012 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5013 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5014
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5015 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5016 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5017 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5018 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5019 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5020 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5021 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5022 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5023 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5024
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5025 # Define an object method and a protected method with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5026 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5027 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5028
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5029 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5030 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5031 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5032 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5033 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5034 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5035 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5036 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5037 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5038
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5039 # Call a public method and a protected method from a protected method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5040 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5041 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5042
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5043 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5044 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5045 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5046 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5047 def _Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5048 return 200
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5049 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5050 def _Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5051 assert_equal(100, this.Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5052 assert_equal(200, this._Bar())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5053 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5054 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5055 this._Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5056 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5057 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5058 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5059 a.T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5060 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5061 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5062
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5063 # Try calling a protected method from another class
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5064 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5065 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5066
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5067 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5068 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5069 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5070 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5071 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5072 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5073 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5074 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5075 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5076 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5077 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5078 var b = B.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5079 b.Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5080 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5081 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5082
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5083 # Call a protected object method from a child class object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5084 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5085 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5086 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5087 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5088 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5089 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5090 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5091 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5092 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5093 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5094 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5095 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5096 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5097 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5098 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5099 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5100 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5101 assert_equal(1234, c.Baz())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5102 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5103 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5104
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5105 # Call a protected object method from a child class object
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5106 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5107 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5108 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5109 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5110 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5111 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5112 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5113 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5114 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5115 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5116 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5117 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5118 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5119 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5120 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5121 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5122 assert_equal(1234, c._Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5123 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5124 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 16)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5125
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5126 # Using "_" prefix in a method name should fail outside of a class
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5127 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5128 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5129 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5130 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5131 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5132 var a = _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5133 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5134 v9.CheckSourceFailure(lines, 'E1267: Function name must start with a capital: _Foo(): number', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5135 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5136
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5137 " Test for an protected class method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5138 def Test_private_class_method()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5139 # Try calling a class protected method (at the script level)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5140 var lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5141 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5142
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5143 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5144 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5145 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5146 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5147 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5148 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5149 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5150 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 8)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5151
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5152 # Try calling a class protected method (from a def function)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5153 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5154 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5155
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5156 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5157 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5158 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5159 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5160 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5161 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5162 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5163 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5164 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5165 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5166 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5167
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5168 # Try calling a class protected method using an object (at the script level)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5169 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5170 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5171
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5172 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5173 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5174 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5175 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5176 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5177 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5178 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5179 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5180 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 9)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5181
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5182 # Try calling a class protected method using an object (from a def function)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5183 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5184 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5185
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5186 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5187 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5188 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5189 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5190 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5191 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5192 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5193 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5194 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5195 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5196 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5197 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5198
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5199 # Use a class protected method from an object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5200 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5201 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5202
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5203 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5204 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5205 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5206 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5207 def Bar()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5208 assert_equal(1234, _Foo())
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5209 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5210 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5211 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5212 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5213 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5214 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5215
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5216 # Use a class protected method from another class protected method without the
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5217 # class name prefix.
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5218 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5219 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5220
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5221 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5222 static def _Foo1(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5223 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5224 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5225 static def _Foo2()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5226 assert_equal(1234, _Foo1())
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5227 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5228 def Bar()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5229 _Foo2()
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5230 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5231 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5232 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5233 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5234 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5235 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5236
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5237 # Declare a class method and a class protected method with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5238 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5239 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5240
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5241 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5242 static def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5243 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5244 static def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5245 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5246 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5247 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5248 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5249 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5250
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5251 # Try calling a class protected method from another class
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5252 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5253 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5254
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5255 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5256 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5257 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5258 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5259 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5260 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5261 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5262 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5263 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5264 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5265 var b = B.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5266 assert_equal(1234, b.Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5267 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5268 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5269
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5270 # Call a protected class method from a child class object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5271 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5272 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5273 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5274 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5275 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5276 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5277 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5278 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5279 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5280 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5281 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5282 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5283 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5284 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5285 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5286 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5287 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5288 assert_equal(1234, c.Baz())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5289 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5290 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5291
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5292 # Call a protected class method from a child class protected class method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5293 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5294 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5295 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5296 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5297 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5298 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5299 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5300 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5301 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5302 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5303 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5304 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5305 static def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5306 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5307 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5308 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5309 assert_equal(1234, C.Baz())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5310 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5311 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5312
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5313 # Call a protected class method from a child class object
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5314 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5315 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5316 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5317 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5318 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5319 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5320 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5321 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5322 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5323 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5324 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5325 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5326 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5327 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5328 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5329 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5330 assert_equal(1234, C._Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5331 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
5332 v9.CheckSourceFailure(lines, 'E1325: Method "_Foo" not found in class "C"', 16)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5333 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5334
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5335 " Test for using the return value of a class/object method as a function
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5336 " argument.
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5337 def Test_objmethod_funcarg()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5338 var lines =<< trim END
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5339 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5340
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5341 class C
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5342 def Foo(): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5343 return 'foo'
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5344 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5345 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5346
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5347 def Bar(a: number, s: string): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5348 return s
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5349 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5350
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5351 def Baz(c: C)
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5352 assert_equal('foo', Bar(10, c.Foo()))
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5353 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5354
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5355 var t = C.new()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5356 Baz(t)
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5357 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5358 v9.CheckSourceSuccess(lines)
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5359
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5360 lines =<< trim END
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5361 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5362
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5363 class C
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5364 static def Foo(): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5365 return 'foo'
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5366 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5367 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5368
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5369 def Bar(a: number, s: string): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5370 return s
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5371 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5372
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5373 def Baz()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5374 assert_equal('foo', Bar(10, C.Foo()))
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5375 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5376
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5377 Baz()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5378 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5379 v9.CheckSourceSuccess(lines)
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5380 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5381
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5382 def Test_static_inheritence()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5383 # subclasses get their own static copy
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5384 var lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5385 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5386
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5387 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5388 static var _svar: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5389 var _mvar: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5390 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5391 _svar = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5392 this._mvar = 101
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5393 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5394 def AccessObject(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5395 return this._mvar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5396 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5397 def AccessStaticThroughObject(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5398 return _svar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5399 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5400 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5401
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5402 class B extends A
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5403 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5404 this._mvar = 102
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5405 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5406 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5407
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5408 class C extends B
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5409 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5410 this._mvar = 103
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5411 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5412
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5413 def AccessPrivateStaticThroughClassName(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5414 assert_equal(1, A._svar)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5415 return 444
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5416 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5417 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5418
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5419 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5420 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5421 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5422 assert_equal(101, oa.AccessObject())
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5423 assert_equal(102, ob.AccessObject())
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5424 assert_equal(103, oc.AccessObject())
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5425
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5426 assert_fails('echo oc.AccessPrivateStaticThroughClassName()', 'E1333: Cannot access protected variable "_svar" in class "A"')
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5427
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5428 # verify object properly resolves to correct static
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5429 assert_equal(1, oa.AccessStaticThroughObject())
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5430 assert_equal(1, ob.AccessStaticThroughObject())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5431 assert_equal(1, oc.AccessStaticThroughObject())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5432 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5433 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5434 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5435
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5436 " Test for declaring duplicate object and class members
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5437 def Test_dup_member_variable()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5438 # Duplicate member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5439 var lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5440 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5441 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5442 var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5443 var val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5444 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5445 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5446 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5447
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5448 # Duplicate protected member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5449 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5450 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5451 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5452 var _val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5453 var _val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5454 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5455 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5456 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5457
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5458 # Duplicate public member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5459 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5460 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5461 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5462 public var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5463 public var val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5464 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5465 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5466 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5467
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5468 # Duplicate protected member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5469 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5470 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5471 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5472 var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5473 var _val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5474 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5475 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5476 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5477
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5478 # Duplicate public and protected member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5479 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5480 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5481 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5482 var _val = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5483 public var val = 10
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5484 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5485 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5486 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5487
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5488 # Duplicate class member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5489 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5490 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5491 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5492 static var s: string = "abc"
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5493 static var _s: string = "def"
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5494 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5495 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5496 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _s', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5497
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5498 # Duplicate public and protected class member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5499 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5500 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5501 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5502 public static var s: string = "abc"
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5503 static var _s: string = "def"
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5504 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5505 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5506 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _s', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5507
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5508 # Duplicate class and object member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5509 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5510 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5511 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5512 static var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5513 var val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5514 def new()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5515 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5516 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5517 var c = C.new()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5518 assert_equal(10, C.val)
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5519 assert_equal(20, c.val)
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5520 END
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
5521 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5522
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5523 # Duplicate object member variable in a derived class
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5524 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5525 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5526 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5527 var val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5528 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5529 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5530 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5531 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5532 var val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5533 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5534 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5535 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 9)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5536
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5537 # Duplicate object protected member variable in a derived class
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5538 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5539 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5540 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5541 var _val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5542 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5543 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5544 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5545 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5546 var _val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5547 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5548 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5549 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 9)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5550
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5551 # Duplicate object protected member variable in a derived class
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5552 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5553 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5554 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5555 var val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5556 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5557 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5558 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5559 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5560 var _val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5561 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5562 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5563 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 9)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5564
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5565 # Duplicate object member variable in a derived class
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5566 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5567 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5568 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5569 var _val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5570 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5571 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5572 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5573 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5574 var val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5575 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5576 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5577 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 9)
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5578
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5579 # Two member variables with a common prefix
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5580 lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5581 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5582 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5583 public static var svar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5584 public static var svar: number
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5585 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5586 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5587 v9.CheckSourceSuccess(lines)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5588 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5589
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5590 " Test for accessing a protected member outside a class in a def function
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5591 def Test_private_member_access_outside_class()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5592 # protected object member variable
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5593 var lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5594 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5595 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5596 var _val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5597 def GetVal(): number
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5598 return this._val
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5599 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5600 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5601 def T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5602 var a = A.new()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5603 a._val = 20
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5604 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5605 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5606 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5607 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_val" in class "A"', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5608
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5609 # access a non-existing protected object member variable
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5610 lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5611 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5612 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5613 var _val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5614 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5615 def T()
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5616 var a = A.new()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5617 a._a = 1
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5618 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5619 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5620 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
5621 v9.CheckSourceFailure(lines, 'E1326: Variable "_a" not found in object "A"', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5622
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5623 # protected static member variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5624 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5625 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5626 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5627 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5628 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5629 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5630 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5631 var x = a._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5632 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5633 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5634 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5635 v9.CheckSourceFailure(lines, 'E1375: Class variable "_val" accessible only using class "A"', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5636
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5637 # protected static member variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5638 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5639 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5640 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5641 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5642 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5643 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5644 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5645 a._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5646 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5647 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5648 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5649 v9.CheckSourceFailure(lines, 'E1375: Class variable "_val" accessible only using class "A"', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5650
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5651 # protected static class variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5652 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5653 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5654 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5655 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5656 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5657 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5658 var x = A._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5659 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5660 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5661 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5662 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_val" in class "A"', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5663
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5664 # protected static class variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5665 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5666 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5667 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5668 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5669 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5670 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5671 A._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5672 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5673 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5674 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5675 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_val" in class "A"', 1)
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5676 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5677
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5678 " Test for changing the member access of an interface in a implementation class
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5679 def Test_change_interface_member_access()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5680 var lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5681 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5682 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5683 var val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5684 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5685 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5686 public var val = 10
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5687 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5688 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5689 v9.CheckSourceFailure(lines, 'E1367: Access level of variable "val" of interface "A" is different', 7)
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5690
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5691 lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5692 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5693 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5694 var val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5695 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5696 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5697 public var val = 10
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5698 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5699 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5700 v9.CheckSourceFailure(lines, 'E1367: Access level of variable "val" of interface "A" is different', 7)
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5701 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5702
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5703 " Test for trying to change a readonly member from a def function
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5704 def Test_readonly_member_change_in_def_func()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5705 var lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5706 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5707 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5708 var val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5709 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5710 def T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5711 var a = A.new()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5712 a.val = 20
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5713 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5714 T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5715 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5716 v9.CheckSourceFailure(lines, 'E1335: Variable "val" in class "A" is not writable', 2)
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5717 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5718
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5719 " Test for reading and writing a class member from a def function
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5720 def Test_modify_class_member_from_def_function()
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5721 var lines =<< trim END
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5722 vim9script
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5723 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5724 var var1: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5725 public static var var2: list<number> = [1, 2]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5726 public static var var3: dict<number> = {a: 1, b: 2}
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5727 static var _priv_var4: number = 40
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5728 endclass
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5729 def T()
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5730 assert_equal([1, 2], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5731 assert_equal({a: 1, b: 2}, A.var3)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5732 A.var2 = [3, 4]
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5733 A.var3 = {c: 3, d: 4}
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5734 assert_equal([3, 4], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5735 assert_equal({c: 3, d: 4}, A.var3)
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5736 assert_fails('echo A._priv_var4', 'E1333: Cannot access protected variable "_priv_var4" in class "A"')
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5737 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5738 T()
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5739 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5740 v9.CheckSourceSuccess(lines)
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5741 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5742
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5743 " Test for accessing a class member variable using an object
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5744 def Test_class_variable_access_using_object()
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5745 var lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5746 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5747 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5748 public static var svar1: list<number> = [1]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5749 public static var svar2: list<number> = [2]
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5750 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5751
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5752 A.svar1->add(3)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5753 A.svar2->add(4)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5754 assert_equal([1, 3], A.svar1)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5755 assert_equal([2, 4], A.svar2)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5756
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5757 def Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5758 A.svar1->add(7)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5759 A.svar2->add(8)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5760 assert_equal([1, 3, 7], A.svar1)
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5761 assert_equal([2, 4, 8], A.svar2)
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5762 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5763 Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5764 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5765 v9.CheckSourceSuccess(lines)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5766
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5767 # Cannot read from a class variable using an object in script context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5768 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5769 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5770 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5771 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5772 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5773 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5774
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5775 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5776 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5777 END
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
5778 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 8)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5779
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5780 # Cannot write to a class variable using an object in script context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5781 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5782 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5783 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5784 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5785 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5786 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5787
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5788 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5789 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5790 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5791 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 8)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5792
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5793 # Cannot read from a class variable using an object in def method context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5794 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5795 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5796 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5797 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5798 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5799 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5800
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5801 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5802 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5803 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5804 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5805 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5806 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5807 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 2)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5808
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5809 # Cannot write to a class variable using an object in def method context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5810 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5811 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5812 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5813 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5814 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5815 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5816
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5817 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5818 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5819 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5820 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5821 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5822 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5823 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 2)
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5824 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5825
33211
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5826 " Test for using a interface method using a child object
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5827 def Test_interface_method_from_child()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5828 var lines =<< trim END
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5829 vim9script
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5830
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5831 interface A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5832 def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5833 endinterface
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5834
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5835 class B implements A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5836 def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5837 return 'foo'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5838 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5839 endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5840
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5841 class C extends B
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5842 def Bar(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5843 return 'bar'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5844 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5845 endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5846
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5847 def T1(a: A)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5848 assert_equal('foo', a.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5849 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5850
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5851 def T2(b: B)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5852 assert_equal('foo', b.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5853 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5854
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5855 var c = C.new()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5856 T1(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5857 T2(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5858 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5859 v9.CheckSourceSuccess(lines)
33211
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5860 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5861
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5862 " Test for using an interface method using a child object when it is overridden
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5863 " by the child class.
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5864 " FIXME: This test fails.
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5865 " def Test_interface_overridden_method_from_child()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5866 " var lines =<< trim END
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5867 " vim9script
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5868 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5869 " interface A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5870 " def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5871 " endinterface
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5872 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5873 " class B implements A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5874 " def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5875 " return 'b-foo'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5876 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5877 " endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5878 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5879 " class C extends B
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5880 " def Bar(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5881 " return 'bar'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5882 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5883 " def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5884 " return 'c-foo'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5885 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5886 " endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5887 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5888 " def T1(a: A)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5889 " assert_equal('c-foo', a.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5890 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5891 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5892 " def T2(b: B)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5893 " assert_equal('c-foo', b.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5894 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5895 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5896 " var c = C.new()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5897 " T1(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5898 " T2(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5899 " END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5900 " v9.CheckSourceSuccess(lines)
33211
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5901 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5902
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5903 " Test for abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5904 def Test_abstract_method()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5905 # Use two abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5906 var lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5907 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5908 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5909 def M1(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5910 return 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5911 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5912 abstract def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5913 abstract def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5914 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5915 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5916 def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5917 return 20
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5918 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5919 def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5920 return 30
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5921 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5922 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5923 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5924 assert_equal([10, 20, 30], [b.M1(), b.M2(), b.M3()])
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5925 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5926 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5927
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5928 # Don't define an abstract method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5929 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5930 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5931 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5932 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5933 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5934 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5935 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5936 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5937 v9.CheckSourceFailure(lines, 'E1373: Abstract method "Foo" is not implemented', 6)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5938
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5939 # Use abstract method in a concrete class
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5940 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5941 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5942 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5943 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5944 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5945 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5946 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5947 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5948 v9.CheckSourceFailure(lines, 'E1372: Abstract method "abstract def Foo()" cannot be defined in a concrete class', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5949
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5950 # Use abstract method in an interface
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5951 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5952 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5953 interface A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5954 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5955 endinterface
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5956 class B implements A
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5957 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5958 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5959 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5960 END
33700
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5961 v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5962
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5963 # Use abstract static method in an interface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5964 lines =<< trim END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5965 vim9script
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5966 interface A
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5967 abstract static def Foo()
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5968 enddef
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5969 endinterface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5970 END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5971 v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5972
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5973 # Use abstract static variable in an interface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5974 lines =<< trim END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5975 vim9script
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5976 interface A
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5977 abstract static foo: number = 10
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5978 endinterface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5979 END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5980 v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5981
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5982 # Abbreviate the "abstract" keyword
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5983 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5984 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5985 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5986 abs def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5987 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5988 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5989 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: abs def Foo()', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5990
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5991 # Use "abstract" with a member variable
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5992 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5993 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5994 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5995 abstract this.val = 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5996 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5997 END
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5998 v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def"', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5999
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6000 # Use a static abstract method
33708
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
6001 lines =<< trim END
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
6002 vim9script
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
6003 abstract class A
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
6004 abstract static def Foo(): number
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
6005 endclass
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
6006 END
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
6007 v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def"', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6008
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6009 # Type mismatch between abstract method and concrete method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6010 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6011 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6012 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6013 abstract def Foo(a: string, b: number): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6014 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6015 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6016 def Foo(a: number, b: string): list<string>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6017 return []
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6018 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6019 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6020 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6021 v9.CheckSourceFailure(lines, 'E1383: Method "Foo": type mismatch, expected func(string, number): list<number> but got func(number, string): list<string>', 9)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6022
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6023 # Invoke an abstract method from a def function
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6024 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6025 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6026 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6027 abstract def Foo(): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6028 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6029 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6030 def Foo(): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6031 return [3, 5]
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6032 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6033 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6034 def Bar(c: B)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6035 assert_equal([3, 5], c.Foo())
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6036 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6037 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6038 Bar(b)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6039 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6040 v9.CheckSourceSuccess(lines)
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6041
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6042 # Use a static method in an abstract class
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6043 lines =<< trim END
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6044 vim9script
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6045 abstract class A
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6046 static def Foo(): string
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6047 return 'foo'
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6048 enddef
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6049 endclass
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6050 assert_equal('foo', A.Foo())
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6051 END
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6052 v9.CheckSourceSuccess(lines)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6053 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6054
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6055 " Test for calling a class method from a subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6056 def Test_class_method_call_from_subclass()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6057 # class method call from a subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6058 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6059 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6060
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6061 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6062 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6063 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6064 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6065 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6066
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6067 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6068 def Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6069 Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6070 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6071 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6072
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6073 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6074 b.Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6075 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6076 v9.CheckSourceFailure(lines, 'E1384: Class method "Foo" accessible only inside class "A"', 1)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6077 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6078
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6079 " Test for calling a class method using an object in a def function context and
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6080 " script context.
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6081 def Test_class_method_call_using_object()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6082 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6083 var lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6084 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6085 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6086 static def Foo(): list<string>
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6087 return ['a', 'b']
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6088 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6089 def Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6090 assert_equal(['a', 'b'], A.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6091 assert_equal(['a', 'b'], Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6092 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6093 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6094
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6095 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6096 assert_equal(['a', 'b'], A.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6097 var t_a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6098 t_a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6099 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6100
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6101 assert_equal(['a', 'b'], A.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6102 var a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6103 a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6104 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6105 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6106 v9.CheckSourceSuccess(lines)
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6107
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6108 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6109 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6110 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6111 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6112 static def Foo(): string
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6113 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6114 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6115 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6116
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6117 var a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6118 assert_equal('foo', a.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6119 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6120 v9.CheckSourceFailure(lines, 'E1385: Class method "Foo" accessible only using class "A"', 9)
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6121
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6122 # def function context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6123 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6124 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6125 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6126 static def Foo(): string
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6127 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6128 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6129 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6130
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6131 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6132 var a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6133 assert_equal('foo', a.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6134 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6135 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6136 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6137 v9.CheckSourceFailure(lines, 'E1385: Class method "Foo" accessible only using class "A"', 2)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6138 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6139
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6140 def Test_class_variable()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6141 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6142 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6143
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6144 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6145 public static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6146 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6147 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6148 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6149 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6150 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6151 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6152 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6153
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6154 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6155 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6156
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6157 assert_equal(10, A.val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6158 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6159 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6160 a.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6161 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6162 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6163
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6164 def T1(a1: A)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6165 a1.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6166 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6167 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6168 T1(b)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6169
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6170 A.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6171 assert_equal(20, A.val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6172 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6173 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6174
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6175 # Modifying a parent class variable from a child class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6176 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6177 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6178
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6179 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6180 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6181 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6182
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6183 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6184 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6185 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6186 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6187 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6188 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6189 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6190 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6191
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6192 # Reading a parent class variable from a child class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6193 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6194 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6195
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6196 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6197 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6198 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6199
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6200 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6201 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6202 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6203 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6204 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6205 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6206 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6207 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6208
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6209 # Modifying a parent class variable from a child object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6210 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6211 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6212
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6213 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6214 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6215 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6216
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6217 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6218 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6219 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6220 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6221 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6222 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6223 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6224 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6225 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6226
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6227 # Reading a parent class variable from a child object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6228 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6229 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6230
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6231 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6232 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6233 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6234
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6235 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6236 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6237 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6238 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6239 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6240 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6241 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6242 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6243 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6244
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6245 # Modifying a class variable using an object at script level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6246 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6247 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6248
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6249 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6250 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6251 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6252 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6253 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6254 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6255 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 7)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6256
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6257 # Reading a class variable using an object at script level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6258 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6259 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6261 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6262 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6263 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6264 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6265 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6266 END
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
6267 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 7)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6268
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6269 # Modifying a class variable using an object at function level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6270 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6271 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6272
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6273 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6274 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6275 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6276
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6277 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6278 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6279 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6280 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6281 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6282 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6283 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 2)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6284
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6285 # Reading a class variable using an object at function level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6286 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6287 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6288
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6289 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6290 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6291 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6292 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6293 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6294 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6295 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6296 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6297 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6298 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 2)
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6299
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6300 # Use old implicit var declaration syntax (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6301 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6302 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6303
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6304 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6305 static val: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6306 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6307 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6308 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6309
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6310 # Use old implicit var declaration syntax (with initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6311 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6312 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6313
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6314 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6315 static val: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6316 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6317 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6318 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6319
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6320 # Use old implicit var declaration syntax (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6321 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6322 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6323
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6324 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6325 static val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6326 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6327 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6328 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6329
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6330 # Missing ":var" in "var" class variable declaration (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6331 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6332 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6333
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6334 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6335 static var: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6336 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6337 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6338 v9.CheckSourceFailure(lines, 'E1329: Invalid class variable declaration: static var: number', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6339
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6340 # Missing ":var" in "var" class variable declaration (with initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6341 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6342 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6343
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6344 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6345 static var: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6346 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6347 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6348 v9.CheckSourceFailure(lines, 'E1329: Invalid class variable declaration: static var: number = 10', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6349
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6350 # Missing ":var" in "var" class variable declaration (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6351 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6352 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6353
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6354 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6355 static var = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6356 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6357 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6358 v9.CheckSourceFailure(lines, 'E1329: Invalid class variable declaration: static var = 10', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6359
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6360 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6361
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6362 " Test for using a duplicate class method and class variable in a child class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6363 def Test_dup_class_member()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6364 # duplicate class variable, class method and overridden object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6365 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6366 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6367 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6368 static var sval = 100
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6369 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6370 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6371 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6372 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6373 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6374 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6375 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6376
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6377 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6378 static var sval = 200
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6379 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6380 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6381 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6382 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6383 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6384 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6385 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6386
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6387 def T1(aa: A): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6388 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6389 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6390
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6391 def T2(bb: B): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6392 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6393 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6394
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6395 assert_equal(100, A.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6396 assert_equal(200, B.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6397 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6398 assert_equal(100, a.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6399 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6400 assert_equal(200, b.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6401 assert_equal(200, T1(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6402 assert_equal(200, T2(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6403 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6404 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6405
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6406 # duplicate class variable and class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6407 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6408 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6409 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6410 static var sval = 100
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6411 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6412 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6413 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6414 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6415 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6416 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6417 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6418
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6419 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6420 static var sval = 200
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6421 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6422 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6423 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6424 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6425
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6426 def T1(aa: A): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6427 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6428 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6429
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6430 def T2(bb: B): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6431 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6432 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6433
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6434 assert_equal(100, A.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6435 assert_equal(200, B.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6436 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6437 assert_equal(100, a.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6438 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6439 assert_equal(100, b.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6440 assert_equal(100, T1(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6441 assert_equal(100, T2(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6442 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6443 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6444 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6445
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6446 " Test for calling an instance method using the class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6447 def Test_instance_method_call_using_class()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6448 # Invoke an object method using a class in script context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6449 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6450 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6451 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6452 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6453 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6454 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6455 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6456 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6457 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6458 v9.CheckSourceFailure(lines, 'E1386: Object method "Foo" accessible only using class "A" object', 7)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6459
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6460 # Invoke an object method using a class in def function context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6461 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6462 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6463 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6464 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6465 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6466 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6467 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6468 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6469 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6470 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6471 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6472 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6473 v9.CheckSourceFailure(lines, 'E1386: Object method "Foo" accessible only using class "A" object', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6474 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6475
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6476 " Test for duplicate class method and instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6477 def Test_dup_classmethod_objmethod()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6478 # Duplicate instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6479 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6480 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6481 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6482 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6483 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6484 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6485 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6486 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6487 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6488 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6489
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6490 # Duplicate protected instance method
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6491 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6492 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6493 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6494 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6495 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6496 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6497 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6498 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6499 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6500 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6501
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6502 # Duplicate class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6503 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6504 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6505 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6506 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6507 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6508 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6509 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6510 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6511 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6512 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6513
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6514 # Duplicate protected class method
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6515 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6516 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6517 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6518 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6519 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6520 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6521 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6522 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6523 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6524 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6525
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6526 # Duplicate protected class and object method
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6527 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6528 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6529 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6530 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6531 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6532 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6533 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6534 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6535 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6536 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6537 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6538
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6539 " Test for an instance method access level comparison with parent instance
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6540 " methods.
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6541 def Test_instance_method_access_level()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6542 # protected method in subclass
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6543 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6544 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6545 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6546 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6547 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6548 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6549 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6550 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6551 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6552 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6553 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6554 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6555 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6556 v9.CheckSourceFailure(lines, 'E1377: Access level of method "_Foo" is different in class "A"', 11)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6557
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6558 # Public method in subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6559 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6560 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6561 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6562 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6563 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6564 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6565 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6566 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6567 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6568 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6569 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6570 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6571 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6572 v9.CheckSourceFailure(lines, 'E1377: Access level of method "Foo" is different in class "A"', 11)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6573 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6574
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6575 def Test_extend_empty_class()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6576 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6577 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6578 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6579 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6580 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6581 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6582 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6583 public static var rw_class_var = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6584 public var rw_obj_var = 2
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6585 static def ClassMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6586 return 3
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6587 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6588 def ObjMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6589 return 4
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6590 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6591 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6592 assert_equal(1, C.rw_class_var)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6593 assert_equal(3, C.ClassMethod())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6594 var c = C.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6595 assert_equal(2, c.rw_obj_var)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6596 assert_equal(4, c.ObjMethod())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6597 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6598 v9.CheckSourceSuccess(lines)
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6599 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6600
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6601 " A interface cannot have a static variable or a static method or a private
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6602 " variable or a protected method or a public variable
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6603 def Test_interface_with_unsupported_members()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6604 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6605 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6606 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6607 static var num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6608 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6609 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6610 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6611
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6612 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6613 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6614 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6615 static var _num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6616 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6617 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6618 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6619
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6620 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6621 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6622 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6623 public static var num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6624 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6625 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
6626 v9.CheckSourceFailure(lines, 'E1387: public variable not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6627
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6628 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6629 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6630 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6631 public static var num: number
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6632 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6633 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
6634 v9.CheckSourceFailure(lines, 'E1387: public variable not supported in an interface', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6635
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6636 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6637 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6638 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6639 static var _num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6640 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6641 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6642 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6643
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6644 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6645 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6646 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6647 static def Foo(d: dict<any>): list<string>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6648 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6649 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6650 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6651
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6652 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6653 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6654 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6655 static def _Foo(d: dict<any>): list<string>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6656 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6657 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6658 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6659
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6660 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6661 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6662 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6663 var _Foo: list<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6664 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6665 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6666 v9.CheckSourceFailure(lines, 'E1379: Protected variable not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6667
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6668 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6669 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6670 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6671 def _Foo(d: dict<any>): list<string>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6672 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6673 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6674 v9.CheckSourceFailure(lines, 'E1380: Protected method not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6675 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6676
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6677 " Test for extending an interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6678 def Test_extend_interface()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6679 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6680 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6681 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6682 var var1: list<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6683 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6684 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6685 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6686 var var2: dict<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6687 def Bar()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6688 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6689 class C implements A, B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6690 var var1 = [1, 2]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6691 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6692 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6693 var var2 = {a: '1'}
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6694 def Bar()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6695 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6696 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6697 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6698 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6699
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6700 # extending empty interface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6701 lines =<< trim END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6702 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6703 interface A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6704 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6705 interface B extends A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6706 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6707 class C implements B
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6708 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6709 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6710 v9.CheckSourceSuccess(lines)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6711
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6712 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6713 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6714 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6715 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6716 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6717 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6718 var var2: dict<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6719 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6720 class C implements A, B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6721 var var2 = {a: '1'}
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6722 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6723 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6724 v9.CheckSourceFailure(lines, 'E1349: Method "Foo" of interface "A" is not implemented', 10)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6725
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6726 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6727 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6728 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6729 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6730 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6731 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6732 var var2: dict<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6733 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6734 class C implements A, B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6735 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6736 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6737 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6738 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6739 v9.CheckSourceFailure(lines, 'E1348: Variable "var2" of interface "B" is not implemented', 11)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6740
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6741 # interface cannot extend a class
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6742 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6743 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6744 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6745 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6746 interface B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6747 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6748 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6749 v9.CheckSourceFailure(lines, 'E1354: Cannot extend A', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6750
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6751 # class cannot extend an interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6752 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6753 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6754 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6755 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6756 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6757 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6758 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6759 v9.CheckSourceFailure(lines, 'E1354: Cannot extend A', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6760
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6761 # interface cannot implement another interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6762 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6763 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6764 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6765 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6766 interface B implements A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6767 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6768 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6769 v9.CheckSourceFailure(lines, 'E1381: Interface cannot use "implements"', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6770
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6771 # interface cannot extend multiple interfaces
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6772 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6773 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6774 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6775 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6776 interface B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6777 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6778 interface C extends A, B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6779 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6780 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6781 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A, B', 6)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6782
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6783 # Variable type in an extended interface is of different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6784 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6785 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6786 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6787 var val1: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6788 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6789 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6790 var val2: string
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6791 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6792 interface C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6793 var val1: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6794 var val2: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6795 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6796 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6797 v9.CheckSourceFailure(lines, 'E1382: Variable "val1": type mismatch, expected number but got string', 11)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6798 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6799
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6800 " Test for a child class implementing an interface when some of the methods are
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6801 " defined in the parent class.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6802 def Test_child_class_implements_interface()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6803 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6804 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6805
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6806 interface Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6807 def F1(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6808 def F2(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6809 def F3(): list<list<number>>
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6810 var var1: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6811 var var2: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6812 var var3: list<dict<number>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6813 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6814
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6815 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6816 def A1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6817 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6818 def F3(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6819 return [[3]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6820 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6821 var v1: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6822 var var3 = [{c: 30}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6823 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6824
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6825 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6826 def B1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6827 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6828 def F2(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6829 return [[2]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6830 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6831 var v2: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6832 var var2 = [{b: 20}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6833 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6834
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6835 class C extends B implements Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6836 def C1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6837 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6838 def F1(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6839 return [[1]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6840 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6841 var v3: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6842 var var1 = [{a: 10}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6843 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6844
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6845 def T(if: Intf)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6846 assert_equal([[1]], if.F1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6847 assert_equal([[2]], if.F2())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6848 assert_equal([[3]], if.F3())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6849 assert_equal([{a: 10}], if.var1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6850 assert_equal([{b: 20}], if.var2)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6851 assert_equal([{c: 30}], if.var3)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6852 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6853
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6854 var c = C.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6855 T(c)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6856 assert_equal([[1]], c.F1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6857 assert_equal([[2]], c.F2())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6858 assert_equal([[3]], c.F3())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6859 assert_equal([{a: 10}], c.var1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6860 assert_equal([{b: 20}], c.var2)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6861 assert_equal([{c: 30}], c.var3)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6862 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6863 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6864
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6865 # One of the interface methods is not found
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6866 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6867 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6868
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6869 interface Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6870 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6871 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6872 def F3()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6873 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6874
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6875 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6876 def A1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6877 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6878 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6879
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6880 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6881 def B1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6882 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6883 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6884 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6885 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6886
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6887 class C extends B implements Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6888 def C1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6889 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6890 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6891 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6892 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6893 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6894 v9.CheckSourceFailure(lines, 'E1349: Method "F3" of interface "Intf" is not implemented', 26)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6895
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6896 # One of the interface methods is of different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6897 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6898 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6899
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6900 interface Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6901 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6902 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6903 def F3()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6904 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6905
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6906 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6907 def F3(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6908 return 0
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6909 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6910 def A1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6911 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6912 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6913
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6914 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6915 def B1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6916 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6917 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6918 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6919 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6920
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6921 class C extends B implements Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6922 def C1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6923 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6924 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6925 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6926 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6927 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6928 v9.CheckSourceFailure(lines, 'E1383: Method "F3": type mismatch, expected func() but got func(): number', 29)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6929
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6930 # One of the interface variables is not present
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6931 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6932 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6933
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6934 interface Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6935 var var1: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6936 var var2: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6937 var var3: list<dict<number>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6938 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6939
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6940 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6941 var v1: list<list<number>> = [[0]]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6942 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6943
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6944 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6945 var v2: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6946 var var2 = [{b: 20}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6947 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6948
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6949 class C extends B implements Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6950 var v3: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6951 var var1 = [{a: 10}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6952 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6953 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6954 v9.CheckSourceFailure(lines, 'E1348: Variable "var3" of interface "Intf" is not implemented', 21)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6955
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6956 # One of the interface variables is of different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6957 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6958 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6959
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6960 interface Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6961 var var1: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6962 var var2: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6963 var var3: list<dict<number>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6964 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6965
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6966 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6967 var v1: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6968 var var3: list<dict<string>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6969 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6970
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6971 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6972 var v2: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6973 var var2 = [{b: 20}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6974 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6975
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6976 class C extends B implements Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6977 var v3: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6978 var var1 = [{a: 10}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6979 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6980 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6981 v9.CheckSourceFailure(lines, 'E1382: Variable "var3": type mismatch, expected list<dict<number>> but got list<dict<string>>', 22)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6982 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6983
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6984 " Test for extending an interface with duplicate variables and methods
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6985 def Test_interface_extends_with_dup_members()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6986 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6987 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6988 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6989 var n1: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6990 def Foo1(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6991 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6992 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6993 var n2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6994 var n1: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6995 def Foo2(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6996 def Foo1(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6997 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6998 class C implements B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6999 var n1 = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7000 var n2 = 20
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7001 def Foo1(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7002 return 30
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7003 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7004 def Foo2(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7005 return 40
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7006 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7007 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7008 def T1(a: A)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7009 assert_equal(10, a.n1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7010 assert_equal(30, a.Foo1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7011 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7012 def T2(b: B)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7013 assert_equal(10, b.n1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7014 assert_equal(20, b.n2)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7015 assert_equal(30, b.Foo1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7016 assert_equal(40, b.Foo2())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7017 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7018 var c = C.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7019 T1(c)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7020 T2(c)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7021 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7022 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7023 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7024
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7025 " Test for using "any" type for a variable in a sub-class while it has a
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7026 " concrete type in the interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7027 def Test_implements_using_var_type_any()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7028 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7029 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7030 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7031 var val: list<dict<string>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7032 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7033 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7034 var val = [{a: '1'}, {b: '2'}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7035 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7036 var b = B.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7037 assert_equal([{a: '1'}, {b: '2'}], b.val)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7038 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7039 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7040
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7041 # initialize instance variable using a different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7042 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7043 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7044 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7045 var val: list<dict<string>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7046 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7047 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7048 var val = {a: 1, b: 2}
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7049 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7050 var b = B.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7051 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
7052 v9.CheckSourceFailure(lines, 'E1382: Variable "val": type mismatch, expected list<dict<string>> but got dict<number>', 1)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7053 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7054
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7055 " Test for assigning to a member variable in a nested class
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7056 def Test_nested_object_assignment()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7057 var lines =<< trim END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7058 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7059
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7060 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7061 var value: number
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7062 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7063
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7064 class B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7065 var a: A = A.new()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7066 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7067
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7068 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7069 var b: B = B.new()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7070 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7071
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7072 class D
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7073 var c: C = C.new()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7074 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7075
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7076 def T(da: D)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
7077 da.c.b.a.value = 10
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7078 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7079
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7080 var d = D.new()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7081 T(d)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7082 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
7083 v9.CheckSourceFailure(lines, 'E1335: Variable "value" in class "A" is not writable', 1)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7084 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7085
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7086 " Test for calling methods using a null object
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7087 def Test_null_object_method_call()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7088 # Calling a object method using a null object in script context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7089 var lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7090 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7091
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7092 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7093 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7094 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7095 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7096 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7097
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7098 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7099 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7100 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7101 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 10)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7102
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7103 # Calling a object method using a null object in def function context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7104 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7105 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7106
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7107 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7108 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7109 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7110 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7111 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7112
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7113 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7114 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7115 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7116 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7117 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7118 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7119 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7120
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7121 # Calling a object method through another class method using a null object in
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7122 # script context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7123 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7124 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7125
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7126 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7127 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7128 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7129 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7130
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7131 static def Bar(o_any: any)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7132 var o_typed: C = o_any
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7133 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7134 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7135 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7136
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7137 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7138 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7139 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7140 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7141
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7142 # Calling a object method through another class method using a null object in
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7143 # def function context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7144 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7145 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7146
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7147 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7148 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7149 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7150 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7151
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7152 static def Bar(o_any: any)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7153 var o_typed: C = o_any
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7154 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7155 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7156 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7157
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7158 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7159 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7160 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7161 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7162 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7163 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7164 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7165 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7166
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7167 " Test for using a dict as an object member
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7168 def Test_dict_object_member()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7169 var lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7170 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7171
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7172 class Context
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7173 public var state: dict<number> = {}
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7174 def GetState(): dict<number>
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7175 return this.state
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7176 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7177 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7178
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7179 var ctx = Context.new()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7180 ctx.state->extend({a: 1})
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7181 ctx.state['b'] = 2
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7182 assert_equal({a: 1, b: 2}, ctx.GetState())
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7183
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7184 def F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7185 ctx.state['c'] = 3
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7186 assert_equal({a: 1, b: 2, c: 3}, ctx.GetState())
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7187 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7188 F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7189 assert_equal(3, ctx.state.c)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7190 ctx.state.c = 4
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7191 assert_equal(4, ctx.state.c)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7192 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7193 v9.CheckSourceSuccess(lines)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7194 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7195
33337
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7196 " The following test was failing after 9.0.1914. This was caused by using a
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7197 " freed object from a previous method call.
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7198 def Test_freed_object_from_previous_method_call()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7199 var lines =<< trim END
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7200 vim9script
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7201
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7202 class Context
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7203 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7204
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7205 class Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7206 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7207
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7208 def Failure(): Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7209 return Result.new()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7210 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7211
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7212 def GetResult(ctx: Context): Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7213 return Failure()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7214 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7215
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7216 def Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7217 var ctx = Context.new()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7218 var result = GetResult(ctx)
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7219 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7220
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7221 Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7222 END
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7223 v9.CheckSourceSuccess(lines)
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7224 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7225
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7226 " Test for duplicate object and class variable
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7227 def Test_duplicate_variable()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7228 # Object variable name is same as the class variable name
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7229 var lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7230 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7231 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7232 public static var sval: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7233 public var sval: number
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7234 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7235 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7236 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7237 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: sval', 4)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7238
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7239 # Duplicate variable name and calling a class method
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7240 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7241 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7242 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7243 public static var sval: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7244 public var sval: number
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7245 def F1()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7246 echo this.sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7247 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7248 static def F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7249 echo sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7250 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7251 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7252 A.F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7253 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7254 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: sval', 4)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7255
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7256 # Duplicate variable with an empty constructor
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7257 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7258 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7259 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7260 public static var sval: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7261 public var sval: number
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7262 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7263 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7264 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7265 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7266 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7267 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: sval', 4)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7268 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7269
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7270 " Test for using a reserved keyword as a variable name
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7271 def Test_reserved_varname()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7272 for kword in ['true', 'false', 'null', 'null_blob', 'null_dict',
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7273 'null_function', 'null_list', 'null_partial', 'null_string',
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7274 'null_channel', 'null_job', 'super', 'this']
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7275
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7276 var lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7277 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7278 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7279 public var {kword}: list<number> = [1, 2, 3]
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7280 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7281 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7282 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7283 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7284
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7285 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7286 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7287 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7288 public var {kword}: list<number> = [1, 2, 3]
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7289 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7290 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7291 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7292 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7293 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7294 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7295
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7296 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7297 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7298 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7299 public var {kword}: list<number> = [1, 2, 3]
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7300 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7301 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7302 def F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7303 echo this.{kword}
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7304 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7305 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7306 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7307 o.F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7308 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7309 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7310
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7311 # class variable name
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7312 if kword != 'this'
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7313 lines =<< trim eval END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7314 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7315 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7316 public static var {kword}: list<number> = [1, 2, 3]
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7317 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7318 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7319 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7320 endif
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7321 endfor
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7322 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7323
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7324 " Test for checking the type of the arguments and the return value of a object
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7325 " method in an extended class.
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7326 def Test_extended_obj_method_type_check()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7327 var lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7328 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7329
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7330 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7331 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7332 class B extends A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7333 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7334 class C extends B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7335 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7336
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7337 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7338 def Doit(p: B): B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7339 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7340 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7341 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7342
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7343 class Bar extends Foo
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7344 def Doit(p: C): B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7345 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7346 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7347 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7348 END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7349 v9.CheckSourceFailure(lines, 'E1383: Method "Doit": type mismatch, expected func(object<B>): object<B> but got func(object<C>): object<B>', 20)
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7350
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7351 lines =<< trim END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7352 vim9script
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7353
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7354 class A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7355 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7356 class B extends A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7357 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7358 class C extends B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7359 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7360
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7361 class Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7362 def Doit(p: B): B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7363 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7364 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7365 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7366
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7367 class Bar extends Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7368 def Doit(p: B): C
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7369 return C.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7370 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7371 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7372 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7373 v9.CheckSourceSuccess(lines)
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7374
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7375 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7376 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7377
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7378 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7379 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7380 class B extends A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7381 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7382 class C extends B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7383 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7384
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7385 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7386 def Doit(p: B): B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7387 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7388 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7389 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7390
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7391 class Bar extends Foo
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7392 def Doit(p: A): B
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7393 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7394 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7395 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7396 END
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7397 v9.CheckSourceFailure(lines, 'E1383: Method "Doit": type mismatch, expected func(object<B>): object<B> but got func(object<A>): object<B>', 20)
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7398
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7399 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7400 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7402 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7403 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7404 class B extends A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7405 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7406 class C extends B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7407 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7408
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7409 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7410 def Doit(p: B): B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7411 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7412 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7413 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7414
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7415 class Bar extends Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7416 def Doit(p: B): A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7417 return A.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7418 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7419 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7420 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7421 v9.CheckSourceFailure(lines, 'E1383: Method "Doit": type mismatch, expected func(object<B>): object<B> but got func(object<B>): object<A>', 20)
33598
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7422
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7423 # check varargs type mismatch
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7424 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7425 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7426
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7427 class B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7428 def F(...xxx: list<any>)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7429 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7430 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7431 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7432 def F(xxx: list<any>)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7433 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7434 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7435 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7436 v9.CheckSourceFailure(lines, 'E1383: Method "F": type mismatch, expected func(...list<any>) but got func(list<any>)', 10)
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7437 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7438
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7439 " Test type checking for class variable in assignments
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7440 func Test_class_variable_complex_type_check()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7441 " class variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7442 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7443 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7444 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7445 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7446 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7447 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7448 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7449 public static var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7450 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7451 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7452 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7453 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7454 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 9)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7455
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7456 " class variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7457 " class def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7458 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7459 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7460 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7461 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7462 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7463 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7464 public static var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7465 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7466 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7467 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7468 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7469 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7470 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7471 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7472 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7473 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7474
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7475 " class variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7476 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7477 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7478 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7479 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7480 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7481 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7482 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7483 public static var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7484 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7485 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7486 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7487 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7488 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7489 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7490 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7491 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7492
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7493 " class variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7494 " expression type. Try assigning a different type from script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7495 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7496 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7497 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7498 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7499 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7500 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7501 public static var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7502 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7503 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7504 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7505 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7506 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 9)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7507
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7508 " class variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7509 " expression type. Try assigning a different type at class def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7510 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7511 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7512 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7513 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7514 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7515 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7516 public static var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7517 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7518 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7519 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7520 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7521 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7522 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7523 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7524 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7525 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7526
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7527 " class variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7528 " expression type. Try assigning a different type at script def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7529 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7530 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7531 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7532 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7533 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7534 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7535 public static var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7536 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7537 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7538 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7539 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7540 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7541 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7542 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7543 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7544
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7545 " class variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7546 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7547 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7548 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7549 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7550 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7551 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7552 public static var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7553 public static var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7554 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7555 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7556 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7557 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7558 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7559 assert_equal('string', typename(A.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7560 A.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7561 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7562 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7563 A.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7564 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7565 assert_equal('string', typename(A.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7566 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7567 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7568
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7569 " class variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7570 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7571 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7572 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7573 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7574 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7575 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7576 public static var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7577 public static var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7578
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7579 def Bar()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7580 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7581 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7582 assert_equal('string', typename(Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7583 Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7584 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7585 Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7586 assert_equal('string', typename(Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7587 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7588 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7589 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7590 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7591 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7592 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7593 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7594 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7595 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7596 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7597
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7598 " class variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7599 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7600 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7601 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7602 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7603 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7604 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7605 public static var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7606 public static var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7607 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7608
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7609 def Bar()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7610 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7611 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7612 assert_equal('string', typename(A.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7613 A.Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7614 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7615 A.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7616 assert_equal('string', typename(A.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7617 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7618 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7619 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7620 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7621 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7622 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7623 call v9.CheckSourceSuccess(lines)
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7624
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7625 let lines =<< trim END
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7626 vim9script
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7627 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7628 public static var foo = [0z10, 0z20]
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7629 endclass
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7630 assert_equal([0z10, 0z20], A.foo)
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7631 A.foo = [0z30]
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7632 assert_equal([0z30], A.foo)
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7633 var a = A.foo
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7634 assert_equal([0z30], a)
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7635 END
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7636 call v9.CheckSourceSuccess(lines)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7637 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7638
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7639 " Test type checking for object variable in assignments
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7640 func Test_object_variable_complex_type_check()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7641 " object variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7642 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7643 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7644 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7645 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7646 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7647 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7648 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7649 public var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7650 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7651 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7652 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7653 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7654 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7655 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 10)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7656
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7657 " object variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7658 " object def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7659 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7660 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7661 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7662 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7663 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7664 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7665 public var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7666 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7667 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7668 this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7669 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7670 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7671 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7672 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7673 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7674 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7675 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7676
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7677 " object variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7678 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7679 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7680 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7681 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7682 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7683 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7684 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7685 public var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7686 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7687 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7688 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7689 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7690 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7691 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7692 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7693 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7694 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7695 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 2)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7696
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7697 " object variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7698 " expression type. Try assigning a different type from script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7699 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7700 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7701 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7702 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7703 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7704 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7705 public var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7706 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7707 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7708 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7709 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7710 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7711 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 10)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7712
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7713 " object variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7714 " expression type. Try assigning a different type at object def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7715 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7716 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7717 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7718 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7719 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7720 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7721 public var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7722 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7723 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7724 this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7725 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7726 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7727 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7728 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7729 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7730 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7731 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7732
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7733 " object variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7734 " expression type. Try assigning a different type at script def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7735 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7736 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7737 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7738 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7739 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7740 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7741 public var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7742 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7743 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7744 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7745 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7746 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7747 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7748 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7749 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7750 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7751 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 2)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7752
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7753 " object variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7754 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7755 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7756 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7757 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7758 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7759 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7760 public var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7761 public var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7762 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7763
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7764 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7765 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7766 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7767 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7768 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7769 assert_equal('string', typename(a.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7770 a.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7771 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7772 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7773 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7774 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7775 assert_equal('string', typename(a.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7776 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7777 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7778
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7779 " object variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7780 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7781 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7782 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7783 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7784 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7785 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7786 public var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7787 public var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7788
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7789 def Bar()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7790 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(this.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7791 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7792 assert_equal('string', typename(this.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7793 this.Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7794 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(this.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7795 this.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7796 assert_equal('string', typename(this.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7797 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7798 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7799
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7800 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7801 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7802 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7803 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7804 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7805 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7806 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7807 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7808
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7809 " object variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7810 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7811 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7812 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7813 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7814 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7815 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7816 public var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7817 public var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7818 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7819
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7820 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7821 var a = A.new()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7822 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7823 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7824 assert_equal('string', typename(a.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7825 a.Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7826 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7827 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7828 assert_equal('string', typename(a.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7829 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7830 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7831 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7832 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7833 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7834 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7835 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7836 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7837
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7838 " Test for recursively calling an object method. This used to cause an
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7839 " use-after-free error.
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7840 def Test_recursive_object_method_call()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7841 var lines =<< trim END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7842 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7843 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7844 var val: number = 0
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7845 def Foo(): number
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7846 if this.val >= 90
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7847 return this.val
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7848 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7849 this.val += 1
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7850 return this.Foo()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7851 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7852 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7853 var a = A.new()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7854 assert_equal(90, a.Foo())
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7855 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7856 v9.CheckSourceSuccess(lines)
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7857 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7858
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7859 " Test for recursively calling a class method.
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7860 def Test_recursive_class_method_call()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7861 var lines =<< trim END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7862 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7863 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7864 static var val: number = 0
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7865 static def Foo(): number
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7866 if val >= 90
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7867 return val
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7868 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7869 val += 1
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7870 return Foo()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7871 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7872 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7873 assert_equal(90, A.Foo())
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7874 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7875 v9.CheckSourceSuccess(lines)
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7876 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7877
33517
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7878 " Test for checking the argument types and the return type when assigning a
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7879 " funcref to make sure the invariant class type is used.
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7880 def Test_funcref_argtype_returntype_check()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7881 var lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7882 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7883 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7884 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7885 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7886 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7887
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7888 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7889 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7890 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7891
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7892 var Bar: func(A): A = Foo
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7893 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7894 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 11)
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7895
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7896 lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7897 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7898 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7899 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7900 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7901 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7902
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7903 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7904 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7905 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7906
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7907 def Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7908 var Bar: func(A): A = Foo
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7909 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7910 Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7911 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7912 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 1)
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7913 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7914
33598
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7915 def Test_funcref_argtype_invariance_check()
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7916 var lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7917 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7918
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7919 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7920 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7921 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7922 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7923 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7924 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7925
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7926 var Func: func(B): number
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7927 Func = (o: B): number => 3
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7928 assert_equal(3, Func(B.new()))
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7929 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7930 v9.CheckSourceSuccess(lines)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7931
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7932 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7933 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7934
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7935 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7936 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7937 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7938 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7939 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7940 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7941
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7942 var Func: func(B): number
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7943 Func = (o: A): number => 3
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7944 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7945 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<B>): number but got func(object<A>): number', 11)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7946
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7947 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7948 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7949
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7950 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7951 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7952 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7953 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7954 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7955 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7956
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7957 var Func: func(B): number
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7958 Func = (o: C): number => 3
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7959 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7960 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<B>): number but got func(object<C>): number', 11)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7961 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7962
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7963 " Test for using an operator (e.g. +) with an assignment
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7964 def Test_op_and_assignment()
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7965 # Using += with a class variable
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7966 var lines =<< trim END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7967 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7968 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7969 public static var val: list<number> = []
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7970 static def Foo(): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7971 val += [1]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7972 return val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7973 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7974 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7975 def Bar(): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7976 A.val += [2]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7977 return A.val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7978 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7979 assert_equal([1], A.Foo())
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7980 assert_equal([1, 2], Bar())
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7981 A.val += [3]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7982 assert_equal([1, 2, 3], A.val)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7983 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7984 v9.CheckSourceSuccess(lines)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7985
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7986 # Using += with an object variable
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7987 lines =<< trim END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7988 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7989 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7990 public var val: list<number> = []
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7991 def Foo(): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7992 this.val += [1]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7993 return this.val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7994 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7995 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7996 def Bar(bar_a: A): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7997 bar_a.val += [2]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7998 return bar_a.val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7999 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8000 var a = A.new()
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8001 assert_equal([1], a.Foo())
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8002 assert_equal([1, 2], Bar(a))
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8003 a.val += [3]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8004 assert_equal([1, 2, 3], a.val)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8005 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8006 v9.CheckSourceSuccess(lines)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8007 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
8008
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8009 " Test for using an object method as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8010 def Test_object_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8011 # Using object method funcref from a def function
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8012 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8013 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8014 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8015 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8016 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8017 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8018 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8019 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8020 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8021 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8022 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8023 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8024 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8025 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8026 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8027
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8028 # Using object method funcref at the script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8029 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8030 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8031 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8032 def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8033 return {a: 1, b: 2}
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8034 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8035 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8036 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8037 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8038 assert_equal({a: 1, b: 2}, Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8039 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8040 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8041
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8042 # Using object method funcref at the script level
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8043 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8044 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8045 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8046 var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8047 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8048 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8049 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8050 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8051 var a = A.new(345)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8052 var Fn = a.Foo
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8053 assert_equal(345, Fn())
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8054 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8055 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8056
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8057 # Using object method funcref from another object method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8058 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8059 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8060 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8061 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8062 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8063 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8064 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8065 var Fn = this.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8066 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8067 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8068 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8069 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8070 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8071 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8072 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8073
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8074 # Using function() to get a object method funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8075 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8076 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8077 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8078 def Foo(l: list<any>): list<any>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8079 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8080 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8081 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8082 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8083 var Fn = function(a.Foo, [[{a: 1, b: 2}, [3, 4]]])
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8084 assert_equal([{a: 1, b: 2}, [3, 4]], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8085 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8086 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8087
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8088 # Use an object method with a function returning a funcref and then call the
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8089 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8090 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8091 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8092
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8093 def Map(F: func(number): number): func(number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8094 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8095 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8096
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8097 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8098 def Double(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8099 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8100 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8101 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8102
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8103 const math = Math.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8104 assert_equal(48, Map(math.Double)(24))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8105 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8106 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8107
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8108 # Try using a protected object method funcref from a def function
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8109 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8110 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8111 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8112 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8113 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8114 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8115 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8116 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8117 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8118 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8119 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8120 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8121 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8122
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8123 # Try using a protected object method funcref at the script level
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8124 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8125 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8126 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8127 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8128 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8129 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8130 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8131 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8132 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8133 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 7)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8134
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8135 # Using a protected object method funcref from another object method
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8136 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8137 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8138 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8139 def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8140 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8141 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8142 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8143 var Fn = this._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8144 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8145 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8146 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8147 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8148 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8149 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8150 v9.CheckSourceSuccess(lines)
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8151
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8152 # Using object method funcref using call()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8153 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8154 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8155 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8156 var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8157 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8158 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8159 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8160 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8161
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8162 def Bar(obj: A)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8163 assert_equal(123, call(obj.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8164 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8165
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8166 var a = A.new(123)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8167 Bar(a)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8168 assert_equal(123, call(a.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8169 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8170 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8171 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8172
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8173 " Test for using a class method as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8174 def Test_class_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8175 # Using class method funcref in a def function
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8176 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8177 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8178 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8179 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8180 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8181 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8182 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8183 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8184 var Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8185 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8186 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8187 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8188 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8189 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8190
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8191 # Using class method funcref at script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8192 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8193 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8194 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8195 static def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8196 return {a: 1, b: 2}
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8197 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8198 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8199 var Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8200 assert_equal({a: 1, b: 2}, Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8201 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8202 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8203
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8204 # Using class method funcref at the script level
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8205 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8206 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8207 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8208 public static var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8209 static def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8210 return val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8211 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8212 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8213 A.val = 567
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8214 var Fn = A.Foo
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8215 assert_equal(567, Fn())
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8216 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8217 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8218
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8219 # Using function() to get a class method funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8220 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8221 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8222 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8223 static def Foo(l: list<any>): list<any>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8224 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8225 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8226 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8227 var Fn = function(A.Foo, [[{a: 1, b: 2}, [3, 4]]])
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8228 assert_equal([{a: 1, b: 2}, [3, 4]], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8229 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8230 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8231
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8232 # Using a class method funcref from another class method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8233 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8234 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8235 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8236 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8237 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8238 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8239 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8240 var Fn = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8241 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8242 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8243 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8244 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8245 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8246 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8247
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8248 # Use a class method with a function returning a funcref and then call the
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8249 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8250 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8251 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8252
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8253 def Map(F: func(number): number): func(number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8254 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8255 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8256
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8257 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8258 static def StaticDouble(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8259 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8260 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8261 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8262
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8263 assert_equal(48, Map(Math.StaticDouble)(24))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8264 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8265 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8266
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8267 # Try using a protected class method funcref in a def function
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8268 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8269 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8270 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8271 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8272 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8273 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8274 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8275 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8276 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8277 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8278 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8279 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8280
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8281 # Try using a protected class method funcref at script level
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8282 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8283 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8284 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8285 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8286 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8287 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8288 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8289 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8290 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 6)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8291
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8292 # Using a protected class method funcref from another class method
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8293 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8294 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8295 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8296 static def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8297 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8298 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8299 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8300 var Fn = _Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8301 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8302 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8303 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8304 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8305 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8306 v9.CheckSourceSuccess(lines)
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8307
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8308 # Using class method funcref using call()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8309 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8310 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8311 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8312 public static var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8313 static def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8314 return val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8315 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8316 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8317
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8318 def Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8319 A.val = 468
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8320 assert_equal(468, call(A.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8321 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8322 Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8323 assert_equal(468, call(A.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8324 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8325 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8326 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8327
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8328 " Test for using an object member as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8329 def Test_object_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8330 # Using a funcref object variable in an object method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8331 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8332 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8333 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8334 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8335 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8336
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8337 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8338 var Cb: func(number): number = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8339 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8340 assert_equal(200, this.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8341 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8342 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8343
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8344 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8345 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8346 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8347 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8348
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8349 # Using a funcref object variable in a def method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8350 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8351 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8352 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8353 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8354 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8355
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8356 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8357 var Cb: func(number): number = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8358 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8359
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8360 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8361 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8362 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8363 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8364 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8365 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8366 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8367
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8368 # Using a funcref object variable at script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8369 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8370 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8371 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8372 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8373 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8374
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8375 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8376 var Cb: func(number): number = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8377 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8378
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8379 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8380 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8381 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8382 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8383
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8384 # Using a funcref object variable pointing to an object method in an object
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8385 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8386 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8387 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8388 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8389 var Cb: func(number): number = this.Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8390 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8391 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8392 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8393 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8394 assert_equal(200, this.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8395 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8396 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8397
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8398 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8399 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8400 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8401 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8402
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8403 # Using a funcref object variable pointing to an object method in a def
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8404 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8405 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8406 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8407 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8408 var Cb: func(number): number = this.Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8409 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8410 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8411 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8412 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8413
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8414 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8415 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8416 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8417 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8418 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8419 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8420 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8421
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8422 # Using a funcref object variable pointing to an object method at script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8423 # level.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8424 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8425 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8426 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8427 var Cb = this.Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8428 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8429 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8430 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8431 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8432
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8433 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8434 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8435 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8436 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8437 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8438
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8439 " Test for using a class member as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8440 def Test_class_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8441 # Using a funcref class variable in a class method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8442 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8443 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8444 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8445 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8446 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8447
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8448 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8449 static var Cb = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8450 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8451 assert_equal(200, Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8452 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8453 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8454
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8455 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8456 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8457 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8458
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8459 # Using a funcref class variable in a def method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8460 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8461 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8462 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8463 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8464 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8465
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8466 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8467 public static var Cb = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8468 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8469
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8470 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8471 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8472 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8473 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8474 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8475 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8476
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8477 # Using a funcref class variable at script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8478 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8479 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8480 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8481 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8482 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8483
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8484 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8485 public static var Cb = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8486 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8487
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8488 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8489 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8490 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8491
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8492 # Using a funcref class variable pointing to a class method in a class
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8493 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8494 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8495 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8496 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8497 static var Cb: func(number): number
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8498 static def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8499 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8500 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8501 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8502 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8503 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8504 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8505 assert_equal(200, Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8506 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8507 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8508
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8509 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8510 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8511 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8512 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8513
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8514 # Using a funcref class variable pointing to a class method in a def method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8515 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8516 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8517 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8518 static var Cb: func(number): number
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8519 static def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8520 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8521 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8522 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8523 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8524 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8525 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8526
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8527 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8528 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8529 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8530 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8531 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8532 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8533 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8534
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8535 # Using a funcref class variable pointing to a class method at script level.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8536 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8537 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8538 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8539 static var Cb: func(number): number
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8540 static def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8541 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8542 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8543 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8544 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8545 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8546 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8547
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8548 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8549 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8550 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8551 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8552 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8553
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8554 " Test for using object methods as popup callback functions
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8555 def Test_objmethod_popup_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8556 # Use the popup from the script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8557 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8558 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8559
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8560 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8561 var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8562 var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8563
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8564 def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8565 add(this.filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8566 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8567 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8568
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8569 def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8570 this.selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8571 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8572 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8573
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8574 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8575 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8576 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8577 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8578 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8579 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8580 assert_equal(100, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8581 assert_equal(['y'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8582 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8583 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8584 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8585 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8586 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8587 assert_equal(200, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8588 assert_equal(['y', 'n'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8589 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8590 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8591
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8592 # Use the popup from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8593 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8594 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8595
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8596 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8597 var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8598 var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8599
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8600 def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8601 add(this.filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8602 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8603 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8604
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8605 def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8606 this.selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8607 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8608 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8609
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8610 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8611 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8612 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8613 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8614 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8615 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8616 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8617 assert_equal(100, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8618 assert_equal(['y'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8619 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8620 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8621 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8622 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8623 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8624 assert_equal(200, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8625 assert_equal(['y', 'n'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8626 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8627 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8628 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8629 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8630 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8631
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8632 " Test for using class methods as popup callback functions
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8633 def Test_classmethod_popup_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8634 # Use the popup from the script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8635 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8636 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8637
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8638 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8639 static var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8640 static var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8641
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8642 static def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8643 add(filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8644 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8645 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8646
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8647 static def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8648 selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8649 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8650 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8651
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8652 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8653 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8654 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8655 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8656 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8657 assert_equal(100, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8658 assert_equal(['y'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8659 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8660 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8661 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8662 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8663 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8664 assert_equal(200, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8665 assert_equal(['y', 'n'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8666 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8667 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8668
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8669 # Use the popup from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8670 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8671 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8672
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8673 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8674 static var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8675 static var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8676
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8677 static def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8678 add(filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8679 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8680 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8681
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8682 static def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8683 selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8684 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8685 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8686
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8687 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8688 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8689 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8690 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8691 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8692 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8693 assert_equal(100, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8694 assert_equal(['y'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8695 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8696 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8697 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8698 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8699 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8700 assert_equal(200, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8701 assert_equal(['y', 'n'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8702 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8703 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8704 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8705 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8706 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8707
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8708 " Test for using an object method as a timer callback function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8709 def Test_objmethod_timer_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8710 # Use the timer callback from script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8711 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8712 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8713
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8714 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8715 var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8716 def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8717 this.timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8718 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8719 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8720
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8721 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8722 timer_start(0, a.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8723 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8724 while maxWait > 0 && a.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8725 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8726 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8727 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8728 assert_equal(6, a.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8729 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8730 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8731
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8732 # Use the timer callback from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8733 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8734 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8735
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8736 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8737 var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8738 def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8739 this.timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8740 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8741 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8742
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8743 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8744 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8745 timer_start(0, a.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8746 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8747 while maxWait > 0 && a.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8748 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8749 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8750 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8751 assert_equal(6, a.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8752 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8753 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8754 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8755 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8756 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8757
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8758 " Test for using a class method as a timer callback function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8759 def Test_classmethod_timer_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8760 # Use the timer callback from script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8761 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8762 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8763
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8764 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8765 static var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8766 static def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8767 timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8768 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8769 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8770
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8771 timer_start(0, A.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8772 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8773 while maxWait > 0 && A.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8774 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8775 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8776 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8777 assert_equal(6, A.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8778 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8779 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8780
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8781 # Use the timer callback from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8782 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8783 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8784
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8785 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8786 static var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8787 static def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8788 timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8789 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8790 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8791
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8792 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8793 timer_start(0, A.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8794 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8795 while maxWait > 0 && A.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8796 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8797 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8798 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8799 assert_equal(6, A.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8800 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8801 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8802 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8803 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8804 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8805
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8806 " Test for using a class variable as the first and/or second operand of a binary
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8807 " operator.
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8808 def Test_class_variable_as_operands()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8809 var lines =<< trim END
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8810 vim9script
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8811 class Tests
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8812 static var truthy: bool = true
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8813 public static var TruthyFn: func
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8814 static var list: list<any> = []
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8815 static var four: number = 4
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8816 static var str: string = 'hello'
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8817
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8818 static def Str(): string
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8819 return str
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8820 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8821
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8822 static def Four(): number
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8823 return four
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8824 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8825
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8826 static def List(): list<any>
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8827 return list
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8828 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8829
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8830 static def Truthy(): bool
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8831 return truthy
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8832 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8833
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8834 def TestOps()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8835 assert_true(Tests.truthy == truthy)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8836 assert_true(truthy == Tests.truthy)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8837 assert_true(Tests.list isnot [])
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8838 assert_true([] isnot Tests.list)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8839 assert_equal(2, Tests.four >> 1)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8840 assert_equal(16, 1 << Tests.four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8841 assert_equal(8, Tests.four + four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8842 assert_equal(8, four + Tests.four)
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8843 assert_equal('hellohello', Tests.str .. str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8844 assert_equal('hellohello', str .. Tests.str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8845
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8846 # Using class variable for list indexing
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8847 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8848 assert_equal(4, l[Tests.four])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8849 assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8850
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8851 # Using class variable for Dict key
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8852 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8853 assert_equal('abc', d[Tests.str])
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8854 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8855 endclass
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8856
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8857 def TestOps2()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8858 assert_true(Tests.truthy == Tests.Truthy())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8859 assert_true(Tests.Truthy() == Tests.truthy)
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8860 assert_true(Tests.truthy == Tests.TruthyFn())
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8861 assert_true(Tests.TruthyFn() == Tests.truthy)
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8862 assert_true(Tests.list is Tests.List())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8863 assert_true(Tests.List() is Tests.list)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8864 assert_equal(2, Tests.four >> 1)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8865 assert_equal(16, 1 << Tests.four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8866 assert_equal(8, Tests.four + Tests.Four())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8867 assert_equal(8, Tests.Four() + Tests.four)
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8868 assert_equal('hellohello', Tests.str .. Tests.Str())
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8869 assert_equal('hellohello', Tests.Str() .. Tests.str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8870
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8871 # Using class variable for list indexing
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8872 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8873 assert_equal(4, l[Tests.four])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8874 assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8875
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8876 # Using class variable for Dict key
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8877 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8878 assert_equal('abc', d[Tests.str])
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8879 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8880
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8881 Tests.TruthyFn = Tests.Truthy
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8882 var t = Tests.new()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8883 t.TestOps()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8884 TestOps2()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8885
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8886 assert_true(Tests.truthy == Tests.Truthy())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8887 assert_true(Tests.Truthy() == Tests.truthy)
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8888 assert_true(Tests.truthy == Tests.TruthyFn())
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8889 assert_true(Tests.TruthyFn() == Tests.truthy)
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8890 assert_true(Tests.list is Tests.List())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8891 assert_true(Tests.List() is Tests.list)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8892 assert_equal(2, Tests.four >> 1)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8893 assert_equal(16, 1 << Tests.four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8894 assert_equal(8, Tests.four + Tests.Four())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8895 assert_equal(8, Tests.Four() + Tests.four)
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8896 assert_equal('hellohello', Tests.str .. Tests.Str())
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8897 assert_equal('hellohello', Tests.Str() .. Tests.str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8898
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8899 # Using class variable for list indexing
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8900 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8901 assert_equal(4, l[Tests.four])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8902 assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8903
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8904 # Using class variable for Dict key
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8905 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8906 assert_equal('abc', d[Tests.str])
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8907 END
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8908 v9.CheckSourceSuccess(lines)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8909 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8910
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8911 " Test for checking the type of the key used to access an object dict member.
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8912 def Test_dict_member_key_type_check()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8913 var lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8914 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8915
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8916 abstract class State
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8917 var numbers: dict<string> = {0: 'nil', 1: 'unity'}
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8918 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8919
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8920 class Test extends State
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8921 def ObjMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8922 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8923 var z: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8924 [this.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8925 assert_equal({0: 'zero.1', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8926 [this.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8927 assert_equal({0: 'zero.2', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8928 [z, this.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8929 assert_equal({0: 'zero.3', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8930 [this.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8931 assert_equal({0: 'zero.4', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8932 [z, this.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8933 assert_equal({0: 'zero.5', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8934 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8935
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8936 static def ClassMethodTests(that: State)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8937 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8938 var z: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8939 [that.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8940 assert_equal({0: 'zero.1', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8941 [that.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8942 assert_equal({0: 'zero.2', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8943 [z, that.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8944 assert_equal({0: 'zero.3', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8945 [that.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8946 assert_equal({0: 'zero.4', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8947 [z, that.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8948 assert_equal({0: 'zero.5', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8949 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8950
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8951 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8952 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8953
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8954 def newMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8955 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8956 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8957 [this.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8958 assert_equal({0: 'zero.1', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8959 [this.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8960 assert_equal({0: 'zero.2', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8961 [z, this.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8962 assert_equal({0: 'zero.3', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8963 [this.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8964 assert_equal({0: 'zero.4', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8965 [z, this.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8966 assert_equal({0: 'zero.5', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8967 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8968 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8969
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8970 def DefFuncTests(that: Test)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8971 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8972 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8973 [that.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8974 assert_equal({0: 'zero.1', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8975 [that.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8976 assert_equal({0: 'zero.2', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8977 [z, that.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8978 assert_equal({0: 'zero.3', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8979 [that.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8980 assert_equal({0: 'zero.4', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8981 [z, that.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8982 assert_equal({0: 'zero.5', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8983 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8984
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8985 Test.newMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8986 Test.new().ObjMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8987 Test.ClassMethodTests(Test.new())
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8988 DefFuncTests(Test.new())
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8989
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8990 const test: Test = Test.new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8991 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8992 [test.numbers[cursor], cursor] = ['zero', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8993 [cursor, test.numbers[cursor]] = [1, 'one']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8994 assert_equal({0: 'zero', 1: 'one'}, test.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8995 END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8996 v9.CheckSourceSuccess(lines)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8997
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8998 lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8999 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9000
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9001 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
9002 var numbers: dict<string> = {a: '1', b: '2'}
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9003
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9004 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9005 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9006
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9007 def Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9008 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9009 [this.numbers.a, z] = [{}, 10]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9010 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9011 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9012
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9013 var a = A.new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9014 a.Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9015 END
33886
cd7acb9bc4fd patch 9.0.2152: Using type unknown for List/Dict containers
Christian Brabandt <cb@256bit.org>
parents: 33829
diff changeset
9016 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected string but got dict<any>', 2)
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9017
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9018 lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9019 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9020
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9021 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
9022 var numbers: dict<number> = {a: 1, b: 2}
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9023
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9024 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9025 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9026
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9027 def Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9028 var x: string = 'a'
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9029 var y: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9030 [this.numbers[x], y] = [{}, 10]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9031 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9032 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9033
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9034 var a = A.new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9035 a.Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9036 END
33886
cd7acb9bc4fd patch 9.0.2152: Using type unknown for List/Dict containers
Christian Brabandt <cb@256bit.org>
parents: 33829
diff changeset
9037 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got dict<any>', 3)
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9038 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9039
33829
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9040 def Test_compile_many_def_functions_in_funcref_instr()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9041 # This used to crash Vim. This is reproducible only when run on new instance
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9042 # of Vim.
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9043 var lines =<< trim END
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9044 vim9script
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9045
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9046 class A
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9047 def new()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9048 this.TakeFunc(this.F00)
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9049 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9050
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9051 def TakeFunc(F: func)
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9052 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9053
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9054 def F00()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9055 this.F01()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9056 this.F02()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9057 this.F03()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9058 this.F04()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9059 this.F05()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9060 this.F06()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9061 this.F07()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9062 this.F08()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9063 this.F09()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9064 this.F10()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9065 this.F11()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9066 this.F12()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9067 this.F13()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9068 this.F14()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9069 this.F15()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9070 this.F16()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9071 this.F17()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9072 this.F18()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9073 this.F19()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9074 this.F20()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9075 this.F21()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9076 this.F22()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9077 this.F23()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9078 this.F24()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9079 this.F25()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9080 this.F26()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9081 this.F27()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9082 this.F28()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9083 this.F29()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9084 this.F30()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9085 this.F31()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9086 this.F32()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9087 this.F33()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9088 this.F34()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9089 this.F35()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9090 this.F36()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9091 this.F37()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9092 this.F38()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9093 this.F39()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9094 this.F40()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9095 this.F41()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9096 this.F42()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9097 this.F43()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9098 this.F44()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9099 this.F45()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9100 this.F46()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9101 this.F47()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9102 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9103
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9104 def F01()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9105 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9106 def F02()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9107 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9108 def F03()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9109 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9110 def F04()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9111 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9112 def F05()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9113 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9114 def F06()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9115 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9116 def F07()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9117 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9118 def F08()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9119 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9120 def F09()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9121 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9122 def F10()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9123 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9124 def F11()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9125 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9126 def F12()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9127 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9128 def F13()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9129 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9130 def F14()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9131 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9132 def F15()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9133 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9134 def F16()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9135 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9136 def F17()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9137 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9138 def F18()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9139 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9140 def F19()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9141 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9142 def F20()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9143 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9144 def F21()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9145 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9146 def F22()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9147 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9148 def F23()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9149 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9150 def F24()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9151 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9152 def F25()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9153 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9154 def F26()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9155 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9156 def F27()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9157 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9158 def F28()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9159 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9160 def F29()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9161 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9162 def F30()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9163 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9164 def F31()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9165 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9166 def F32()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9167 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9168 def F33()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9169 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9170 def F34()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9171 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9172 def F35()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9173 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9174 def F36()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9175 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9176 def F37()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9177 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9178 def F38()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9179 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9180 def F39()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9181 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9182 def F40()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9183 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9184 def F41()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9185 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9186 def F42()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9187 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9188 def F43()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9189 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9190 def F44()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9191 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9192 def F45()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9193 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9194 def F46()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9195 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9196 def F47()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9197 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9198 endclass
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9199
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9200 A.new()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9201 END
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9202 writefile(lines, 'Xscript', 'D')
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9203 g:RunVim([], [], '-u NONE -S Xscript -c qa')
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9204 assert_equal(0, v:shell_error)
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9205 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9206
33951
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9207 " Test for 'final' class and object variables
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9208 def Test_final_class_object_variable()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9209 # Test for changing a final object variable from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9210 var lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9211 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9212 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9213 final foo: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9214 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9215 this.foo = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9216 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9217 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9218 defcompile A.Foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9219 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9220 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "foo" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9221
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9222 # Test for changing a final object variable from the 'new' function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9223 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9224 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9225 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9226 final s1: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9227 final s2: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9228 def new(this.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9229 this.s2 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9230 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9231 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9232 var a = A.new('abc')
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9233 assert_equal('abc', a.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9234 assert_equal('def', a.s2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9235 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9236 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9237
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9238 # Test for a final class variable
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9239 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9240 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9241 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9242 static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9243 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9244 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9245 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9246 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9247
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9248 # Test for changing a final class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9249 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9250 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9251 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9252 static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9253 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9254 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9255 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9256 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9257 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9258 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9259 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9260
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9261 # Test for changing a public final class variable at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9262 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9263 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9264 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9265 public static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9266 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9267 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9268 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9269 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9270 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9271
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9272 # Test for changing a public final class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9273 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9274 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9275 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9276 public static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9277 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9278 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9279 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9280 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9281 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9282 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9283 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9284
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9285 # Test for changing a public final class variable from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9286 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9287 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9288 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9289 public static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9290 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9291 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9292 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9293 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9294 defcompile
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9295 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9296 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9297
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9298 # Test for using a final variable of composite type
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9299 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9300 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9301 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9302 public final l: list<number>
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9303 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9304 this.l = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9305 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9306 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9307 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9308 this.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9309 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9310 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9311 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9312 assert_equal([1, 2], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9313 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9314 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9315 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9316 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9317
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9318 # Test for changing a final variable of composite type from another object
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9319 # function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9320 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9321 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9322 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9323 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9324 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9325 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9326 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9327 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9328 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9329 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9330 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9331 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9332
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9333 # Test for modifying a final variable of composite type at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9334 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9335 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9336 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9337 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9338 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9339 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9340 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9341 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9342 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9343 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9344 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9345
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9346 # Test for modifying a final variable of composite type from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9347 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9348 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9349 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9350 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9351 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9352 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9353 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9354 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9355 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9356 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9357 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9358 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9359 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9360 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9361
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9362 # Test for modifying a final variable of composite type from another object
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9363 # function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9364 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9365 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9366 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9367 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9368 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9369 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9370 this.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9371 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9372 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9373 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9374 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9375 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9376 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9377 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9378
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9379 # Test for assigning a new value to a final variable of composite type at
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9380 # script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9381 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9382 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9383 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9384 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9385 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9386 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9387 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9388 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9389 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9390
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9391 # Test for assigning a new value to a final variable of composite type from
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9392 # another object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9393 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9394 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9395 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9396 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9397 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9398 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9399 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9400 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9401 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9402 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9403 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9404 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9405
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9406 # Test for assigning a new value to a final variable of composite type from
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9407 # another function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9408 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9409 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9410 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9411 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9412 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9413 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9414 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9415 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9416 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9417 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9418 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9419 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9420
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9421 # Error case: Use 'final' with just a variable name
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9422 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9423 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9424 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9425 final foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9426 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9427 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9428 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9429 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9430
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9431 # Error case: Use 'final' followed by 'public'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9432 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9433 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9434 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9435 final public foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9436 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9437 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9438 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9439 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9440
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9441 # Error case: Use 'final' followed by 'static'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9442 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9443 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9444 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9445 final static foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9446 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9447 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9448 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9449 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9450
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9451 # Error case: 'final' cannot be used in an interface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9452 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9453 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9454 interface A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9455 final foo: number = 10
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9456 endinterface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9457 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9458 v9.CheckSourceFailure(lines, 'E1408: Final variable not supported in an interface', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9459
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9460 # Error case: 'final' not supported for an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9461 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9462 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9463 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9464 final def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9465 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9466 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9467 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9468 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9469
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9470 # Error case: 'final' not supported for a class method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9471 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9472 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9473 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9474 static final def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9475 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9476 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9477 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9478 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9479 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9480
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9481 " Test for 'const' class and object variables
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9482 def Test_const_class_object_variable()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9483 # Test for changing a const object variable from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9484 var lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9485 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9486 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9487 const foo: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9488 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9489 this.foo = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9490 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9491 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9492 defcompile A.Foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9493 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9494 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "foo" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9495
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9496 # Test for changing a const object variable from the 'new' function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9497 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9498 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9499 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9500 const s1: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9501 const s2: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9502 def new(this.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9503 this.s2 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9504 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9505 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9506 var a = A.new('abc')
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9507 assert_equal('abc', a.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9508 assert_equal('def', a.s2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9509 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9510 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9511
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9512 # Test for changing a const object variable from an object method called from
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9513 # the 'new' function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9514 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9515 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9516 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9517 const s1: string = 'abc'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9518 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9519 this.ChangeStr()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9520 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9521 def ChangeStr()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9522 this.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9523 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9524 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9525 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9526 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9527 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9528
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9529 # Test for a const class variable
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9530 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9531 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9532 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9533 static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9534 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9535 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9536 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9537 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9538
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9539 # Test for changing a const class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9540 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9541 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9542 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9543 static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9544 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9545 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9546 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9547 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9548 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9549 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9550 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9551
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9552 # Test for changing a public const class variable at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9553 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9554 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9555 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9556 public static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9557 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9558 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9559 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9560 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9561 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9562
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9563 # Test for changing a public const class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9564 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9565 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9566 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9567 public static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9568 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9569 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9570 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9571 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9572 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9573 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9574 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9575
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9576 # Test for changing a public const class variable from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9577 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9578 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9579 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9580 public static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9581 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9582 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9583 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9584 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9585 defcompile
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9586 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9587 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9588
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9589 # Test for changing a const List item from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9590 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9591 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9592 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9593 public const l: list<number>
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9594 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9595 this.l = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9596 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9597 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9598 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9599 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9600 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9601 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9602 assert_equal([1, 2], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9603 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9604 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9605 v9.CheckSourceFailure(lines, 'E1119: Cannot change locked list item', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9606
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9607 # Test for adding a value to a const List from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9608 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9609 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9610 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9611 public const l: list<number>
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9612 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9613 this.l = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9614 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9615 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9616 this.l->add(3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9617 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9618 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9619 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9620 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9621 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9622 v9.CheckSourceFailure(lines, 'E741: Value is locked: add() argument', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9623
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9624 # Test for reassigning a const List from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9625 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9626 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9627 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9628 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9629 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9630 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9631 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9632 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9633 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9634 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9635 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9636 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9637
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9638 # Test for changing a const List item at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9639 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9640 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9641 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9642 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9643 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9644 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9645 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9646 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9647 v9.CheckSourceFailure(lines, 'E741: Value is locked:', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9648
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9649 # Test for adding a value to a const List item at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9650 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9651 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9652 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9653 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9654 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9655 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9656 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9657 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9658 v9.CheckSourceFailure(lines, 'E741: Value is locked:', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9659
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9660 # Test for changing a const List item from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9661 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9662 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9663 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9664 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9665 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9666 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9667 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9668 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9669 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9670 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9671 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9672 v9.CheckSourceFailure(lines, 'E1119: Cannot change locked list item', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9673
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9674 # Test for adding a value to a const List item from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9675 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9676 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9677 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9678 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9679 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9680 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9681 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9682 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9683 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9684 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9685 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9686 v9.CheckSourceFailure(lines, 'E741: Value is locked: add() argument', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9687
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9688 # Test for changing a const List item from an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9689 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9690 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9691 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9692 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9693 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9694 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9695 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9696 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9697 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9698 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9699 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9700 v9.CheckSourceFailure(lines, 'E1119: Cannot change locked list item', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9701
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9702 # Test for adding a value to a const List item from an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9703 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9704 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9705 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9706 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9707 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9708 this.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9709 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9710 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9711 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9712 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9713 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9714 v9.CheckSourceFailure(lines, 'E741: Value is locked: add() argument', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9715
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9716 # Test for reassigning a const List object variable at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9717 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9718 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9719 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9720 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9721 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9722 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9723 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9724 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9725 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9726
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9727 # Test for reassigning a const List object variable from an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9728 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9729 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9730 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9731 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9732 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9733 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9734 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9735 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9736 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9737 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9738 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9739 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9740
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9741 # Test for reassigning a const List object variable from another function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9742 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9743 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9744 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9745 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9746 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9747 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9748 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9749 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9750 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9751 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9752 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9753 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9754
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9755 # Error case: Use 'const' with just a variable name
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9756 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9757 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9758 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9759 const foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9760 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9761 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9762 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9763 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9764
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9765 # Error case: Use 'const' followed by 'public'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9766 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9767 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9768 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9769 const public foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9770 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9771 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9772 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9773 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9774
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9775 # Error case: Use 'const' followed by 'static'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9776 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9777 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9778 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9779 const static foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9780 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9781 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9782 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9783 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9784
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9785 # Error case: 'const' cannot be used in an interface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9786 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9787 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9788 interface A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9789 const foo: number = 10
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9790 endinterface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9791 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9792 v9.CheckSourceFailure(lines, 'E1410: Const variable not supported in an interface', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9793
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9794 # Error case: 'const' not supported for an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9795 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9796 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9797 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9798 const def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9799 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9800 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9801 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9802 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9803
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9804 # Error case: 'const' not supported for a class method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9805 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9806 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9807 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9808 static const def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9809 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9810 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9811 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9812 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9813 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9814
34112
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9815 " Test for compiling class/object methods using :defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9816 def Test_defcompile_class()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9817 # defcompile all the classes in the current script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9818 var lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9819 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9820 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9821 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9822 var i = 10
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9823 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9824 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9825 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9826 def Bar()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9827 var i = 20
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9828 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9829 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9830 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9831 defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9832 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9833 v9.CheckSourceFailure(lines, 'E476: Invalid command: xxx', 2)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9834
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9835 # defcompile a specific class
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9836 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9837 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9838 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9839 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9840 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9841 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9842 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9843 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9844 def Bar()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9845 yyy
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9846 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9847 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9848 defcompile B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9849 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9850 v9.CheckSourceFailure(lines, 'E476: Invalid command: yyy', 1)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9851
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9852 # defcompile a non-class
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9853 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9854 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9855 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9856 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9857 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9858 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9859 var X: list<number> = []
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9860 defcompile X
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9861 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9862 v9.CheckSourceFailure(lines, 'E1061: Cannot find function X', 7)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9863
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9864 # defcompile a class twice
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9865 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9866 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9867 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9868 def new()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9869 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9870 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9871 defcompile A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9872 defcompile A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9873 assert_equal('Function A.new does not need compiling', v:statusmsg)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9874 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9875 v9.CheckSourceSuccess(lines)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9876
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9877 # defcompile should not compile an imported class
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9878 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9879 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9880 export class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9881 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9882 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9883 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9884 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9885 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9886 writefile(lines, 'Xdefcompileimport.vim', 'D')
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9887 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9888 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9889
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9890 import './Xdefcompileimport.vim'
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9891 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9892 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9893 defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9894 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9895 v9.CheckScriptSuccess(lines)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9896 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9897
34472
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9898 " Test for cases common to all the object builtin methods
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9899 def Test_object_builtin_method()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9900 var lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9901 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9902 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9903 def abc()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9904 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9905 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9906 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9907 v9.CheckSourceFailure(lines, 'E1267: Function name must start with a capital: abc()', 3)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9908
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9909 for funcname in ["len", "string", "empty"]
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9910 lines =<< trim eval END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9911 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9912 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9913 static def {funcname}(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9914 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9915 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9916 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9917 v9.CheckSourceFailure(lines, 'E1413: Builtin class method not supported', 3)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9918 endfor
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9919 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9920
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9921 " Test for using the empty() builtin method with an object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9922 " This is a legacy function to use the test_garbagecollect_now() function.
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9923 func Test_object_empty()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9924 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9925 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9926 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9927 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9928 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9929 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9930 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9931
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9932 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9933 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9934 assert_equal(true, empty(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9935 assert_equal(true, afoo->empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9936 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9937
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9938 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9939 assert_equal(1, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9940 assert_equal(1, a->empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9941 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9942 assert_equal(1, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9943 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9944 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9945 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9946 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9947 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9948
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9949 " empty() should return 1 without a builtin method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9950 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9951 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9952 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9953 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9954
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9955 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9956 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9957 assert_equal(1, empty(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9958 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9959
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9960 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9961 assert_equal(1, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9962 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9963 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9964 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9965
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9966 " Unsupported signature for the empty() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9967 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9968 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9969 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9970 def empty()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9971 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9972 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9973 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9974 call v9.CheckSourceFailure(lines, 'E1383: Method "empty": type mismatch, expected func(): bool but got func()', 4)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9975
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9976 " Error when calling the empty() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9977 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9978 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9979 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9980 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9981 throw "Failed to check emptiness"
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9982 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9983 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9984
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9985 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9986 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9987 var i = empty(afoo)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9988 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9989
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9990 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9991 assert_fails('empty(a)', 'Failed to check emptiness')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9992 assert_fails('Foo()', 'Failed to check emptiness')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9993 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9994 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9995
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9996 " call empty() using an object from a script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9997 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9998 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9999 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10000 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10001 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10002 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10003 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10004 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10005 assert_equal(true, afoo.empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10006 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10007 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10008
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10009 " call empty() using an object from a method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10010 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10011 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10012 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10013 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10014 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10015 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10016 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10017 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10018 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10019 assert_equal(true, afoo.empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10020 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10021 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10022 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10023 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10024
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10025 " call empty() using "this" from an object method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10026 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10027 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10028 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10029 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10030 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10031 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10032 def Foo(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10033 return this.empty()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10034 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10035 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10036 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10037 var abar = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10038 assert_equal(true, abar.Foo())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10039 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10040 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10041 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10042 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10043
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10044 " Call empty() from a derived object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10045 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10046 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10047 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10048 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10049 return false
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10050 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10051 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10052 class B extends A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10053 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10054 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10055 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10056 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10057 def Foo(afoo: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10058 assert_equal(true, empty(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10059 var bfoo = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10060 assert_equal(true, empty(bfoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10061 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10062 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10063 assert_equal(1, empty(b))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10064 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10065 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10066 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10067
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10068 " Invoking empty method using an interface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10069 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10070 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10071 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10072 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10073 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10074 class B implements A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10075 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10076 return false
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10077 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10078 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10079 def Foo(a: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10080 assert_equal(false, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10081 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10082 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10083 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10084 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10085 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10086 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10087
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10088 " Test for using the len() builtin method with an object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10089 " This is a legacy function to use the test_garbagecollect_now() function.
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10090 func Test_object_length()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10091 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10092 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10093 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10094 var mylen: number = 0
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10095 def new(n: number)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10096 this.mylen = n
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10097 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10098 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10099 return this.mylen
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10100 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10101 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10102
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10103 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10104 var afoo = A.new(12)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10105 assert_equal(12, len(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10106 assert_equal(12, afoo->len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10107 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10108
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10109 var a = A.new(22)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10110 assert_equal(22, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10111 assert_equal(22, a->len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10112 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10113 assert_equal(22, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10114 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10115 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10116 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10117 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10118 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10119
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10120 " len() should return 0 without a builtin method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10121 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10122 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10123 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10124 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10125
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10126 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10127 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10128 assert_equal(0, len(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10129 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10130
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10131 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10132 assert_equal(0, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10133 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10134 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10135 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10136
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10137 " Unsupported signature for the len() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10138 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10139 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10140 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10141 def len()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10142 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10143 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10144 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10145 call v9.CheckSourceFailure(lines, 'E1383: Method "len": type mismatch, expected func(): number but got func()', 4)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10146
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10147 " Error when calling the len() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10148 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10149 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10150 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10151 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10152 throw "Failed to compute length"
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10153 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10154 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10155
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10156 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10157 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10158 var i = len(afoo)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10159 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10160
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10161 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10162 assert_fails('len(a)', 'Failed to compute length')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10163 assert_fails('Foo()', 'Failed to compute length')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10164 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10165 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10166
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10167 " call len() using an object from a script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10168 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10169 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10170 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10171 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10172 return 5
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10173 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10174 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10175 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10176 assert_equal(5, afoo.len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10177 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10178 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10179
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10180 " call len() using an object from a method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10181 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10182 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10183 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10184 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10185 return 5
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10186 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10187 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10188 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10189 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10190 assert_equal(5, afoo.len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10191 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10192 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10193 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10194 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10195
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10196 " call len() using "this" from an object method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10197 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10198 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10199 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10200 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10201 return 8
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10202 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10203 def Foo(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10204 return this.len()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10205 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10206 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10207 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10208 var abar = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10209 assert_equal(8, abar.Foo())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10210 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10211 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10212 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10213 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10214
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10215 " Call len() from a derived object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10216 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10217 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10218 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10219 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10220 return 10
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10221 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10222 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10223 class B extends A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10224 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10225 return 20
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10226 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10227 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10228 def Foo(afoo: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10229 assert_equal(20, len(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10230 var bfoo = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10231 assert_equal(20, len(bfoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10232 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10233 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10234 assert_equal(20, len(b))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10235 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10236 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10237 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10238
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10239 " Invoking len method using an interface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10240 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10241 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10242 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10243 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10244 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10245 class B implements A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10246 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10247 return 123
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10248 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10249 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10250 def Foo(a: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10251 assert_equal(123, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10252 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10253 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10254 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10255 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10256 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10257 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10258
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10259 " Test for using the string() builtin method with an object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10260 " This is a legacy function to use the test_garbagecollect_now() function.
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10261 func Test_object_string()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10262 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10263 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10264 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10265 var name: string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10266 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10267 return this.name
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10268 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10269 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10270
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10271 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10272 var afoo = A.new("foo-A")
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10273 assert_equal('foo-A', string(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10274 assert_equal('foo-A', afoo->string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10275 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10276
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10277 var a = A.new("script-A")
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10278 assert_equal('script-A', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10279 assert_equal('script-A', a->string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10280 assert_equal(['script-A'], execute('echo a')->split("\n"))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10281 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10282 assert_equal('script-A', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10283 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10284 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10285 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10286 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10287 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10288
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10289 " string() should return "object of A {}" without a builtin method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10290 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10291 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10292 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10293 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10294
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10295 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10296 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10297 assert_equal('object of A {}', string(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10298 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10299
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10300 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10301 assert_equal('object of A {}', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10302 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10303 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10304 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10305
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10306 " Unsupported signature for the string() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10307 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10308 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10309 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10310 def string()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10311 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10312 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10313 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10314 call v9.CheckSourceFailure(lines, 'E1383: Method "string": type mismatch, expected func(): string but got func()', 4)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10315
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10316 " Error when calling the string() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10317 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10318 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10319 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10320 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10321 throw "Failed to get text"
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10322 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10323 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10324
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10325 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10326 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10327 var i = string(afoo)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10328 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10329
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10330 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10331 assert_fails('string(a)', 'Failed to get text')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10332 assert_fails('Foo()', 'Failed to get text')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10333 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10334 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10335
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10336 " call string() using an object from a script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10337 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10338 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10339 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10340 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10341 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10342 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10343 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10344 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10345 assert_equal('A', afoo.string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10346 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10347 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10348
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10349 " call string() using an object from a method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10350 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10351 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10352 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10353 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10354 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10355 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10356 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10357 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10358 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10359 assert_equal('A', afoo.string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10360 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10361 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10362 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10363 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10364
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10365 " call string() using "this" from an object method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10366 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10367 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10368 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10369 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10370 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10371 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10372 def Foo(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10373 return this.string()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10374 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10375 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10376 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10377 var abar = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10378 assert_equal('A', abar.string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10379 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10380 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10381 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10382 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10383
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10384 " Call string() from a derived object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10385 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10386 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10387 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10388 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10389 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10390 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10391 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10392 class B extends A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10393 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10394 return 'B'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10395 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10396 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10397 def Foo(afoo: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10398 assert_equal('B', string(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10399 var bfoo = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10400 assert_equal('B', string(bfoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10401 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10402 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10403 assert_equal('B', string(b))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10404 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10405 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10406 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10407
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10408 " Invoking string method using an interface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10409 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10410 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10411 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10412 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10413 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10414 class B implements A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10415 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10416 return 'B'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10417 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10418 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10419 def Foo(a: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10420 assert_equal('B', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10421 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10422 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10423 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10424 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10425 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10426 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10427
34508
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10428 " Test for using a class in the class definition
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10429 def Test_Ref_Class_Within_Same_Class()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10430 var lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10431 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10432 class A
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10433 var n: number = 0
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10434 def Equals(other: A): bool
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10435 return this.n == other.n
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10436 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10437 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10438
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10439 var a1 = A.new(10)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10440 var a2 = A.new(10)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10441 var a3 = A.new(20)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10442 assert_equal(true, a1.Equals(a2))
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10443 assert_equal(false, a2.Equals(a3))
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10444 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10445 v9.CheckScriptSuccess(lines)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10446
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10447 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10448 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10449
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10450 class Foo
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10451 var num: number
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10452 def Clone(): Foo
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10453 return Foo.new(this.num)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10454 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10455 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10456
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10457 var f1 = Foo.new(1)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10458
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10459 def F()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10460 var f2: Foo = f1.Clone()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10461 assert_equal(false, f2 is f1)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10462 assert_equal(true, f2.num == f1.num)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10463 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10464 F()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10465
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10466 var f3: Foo = f1.Clone()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10467 assert_equal(false, f3 is f1)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10468 assert_equal(true, f3.num == f1.num)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10469 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10470 v9.CheckScriptSuccess(lines)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10471
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10472 # Test for trying to use a class to extend when defining the same class
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10473 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10474 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10475 class A extends A
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10476 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10477 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10478 v9.CheckScriptFailure(lines, 'E1354: Cannot extend A', 3)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10479
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10480 # Test for trying to use a class to implement when defining the same class
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10481 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10482 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10483 class A implements A
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10484 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10485 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10486 v9.CheckScriptFailure(lines, 'E1347: Not a valid interface: A', 3)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10487 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10488
34618
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10489 " Test for using a compound operator from a lambda function in an object method
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10490 def Test_compound_op_in_objmethod_lambda()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10491 # Test using the "+=" operator
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10492 var lines =<< trim END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10493 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10494 class A
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10495 var n: number = 10
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10496 def Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10497 var Fn = () => {
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10498 this.n += 1
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10499 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10500 Fn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10501 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10502 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10503
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10504 var a = A.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10505 a.Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10506 assert_equal(11, a.n)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10507 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10508 v9.CheckScriptSuccess(lines)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10509
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10510 # Test using the "..=" operator
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10511 lines =<< trim END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10512 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10513 class A
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10514 var s: string = "a"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10515 def Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10516 var Fn = () => {
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10517 this.s ..= "a"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10518 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10519 Fn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10520 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10521 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10522
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10523 var a = A.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10524 a.Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10525 a.Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10526 assert_equal("aaa", a.s)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10527 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10528 v9.CheckScriptSuccess(lines)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10529 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10530
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10531 " Test for using test_refcount() with a class and an object
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10532 def Test_class_object_refcount()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10533 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10534 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10535 class A
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10536 endclass
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10537 var a: A = A.new()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10538 assert_equal(2, test_refcount(A))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10539 assert_equal(1, test_refcount(a))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10540 var b = a
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10541 assert_equal(2, test_refcount(A))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10542 assert_equal(2, test_refcount(a))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10543 assert_equal(2, test_refcount(b))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10544 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10545 v9.CheckScriptSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10546 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10547
34618
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10548 " call a lambda function in one object from another object
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10549 def Test_lambda_invocation_across_classes()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10550 var lines =<< trim END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10551 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10552 class A
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10553 var s: string = "foo"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10554 def GetFn(): func
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10555 var Fn = (): string => {
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10556 return this.s
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10557 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10558 return Fn
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10559 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10560 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10561
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10562 class B
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10563 var s: string = "bar"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10564 def GetFn(): func
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10565 var a = A.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10566 return a.GetFn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10567 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10568 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10569
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10570 var b = B.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10571 var Fn = b.GetFn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10572 assert_equal("foo", Fn())
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10573 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10574 v9.CheckScriptSuccess(lines)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10575 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10576
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10577 " Test for using a class member which is an object of the current class
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10578 def Test_current_class_object_class_member()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10579 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10580 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10581 class A
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10582 public static var obj1: A = A.new(10)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10583 var n: number
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10584 endclass
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10585 defcompile
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10586 assert_equal(10, A.obj1.n)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10587 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10588 v9.CheckScriptSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10589 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10590
34748
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10591 " Test for updating a base class variable from a base class method without the
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10592 " class name. This used to crash Vim (Github issue #14352).
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10593 def Test_use_base_class_variable_from_base_class_method()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10594 var lines =<< trim END
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10595 vim9script
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10596
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10597 class DictKeyClass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10598 static var _obj_id_count = 1
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10599 def _GenerateKey()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10600 _obj_id_count += 1
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10601 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10602 static def GetIdCount(): number
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10603 return _obj_id_count
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10604 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10605 endclass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10606
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10607 class C extends DictKeyClass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10608 def F()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10609 this._GenerateKey()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10610 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10611 endclass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10612
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10613 C.new().F()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10614 assert_equal(2, DictKeyClass.GetIdCount())
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10615 END
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10616 v9.CheckScriptSuccess(lines)
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10617 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10618
34769
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10619 " Test for accessing protected funcref object and class variables
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10620 def Test_protected_funcref()
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10621 # protected funcref object variable
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10622 var lines =<< trim END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10623 vim9script
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10624 class Test1
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10625 const _Id: func(any): any = (v) => v
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10626 endclass
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10627 var n = Test1.new()._Id(1)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10628 END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10629 v9.CheckScriptFailure(lines, 'E1333: Cannot access protected variable "_Id" in class "Test1"', 5)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10630
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10631 # protected funcref class variable
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10632 lines =<< trim END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10633 vim9script
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10634 class Test2
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10635 static const _Id: func(any): any = (v) => v
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10636 endclass
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10637 var n = Test2._Id(2)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10638 END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10639 v9.CheckScriptFailure(lines, 'E1333: Cannot access protected variable "_Id" in class "Test2"', 5)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10640 enddef
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10641
34773
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10642 " Test for using lambda block in classes
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10643 def Test_lambda_block_in_class()
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10644 # This used to crash Vim
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10645 var lines =<< trim END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10646 vim9script
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10647 class IdClass1
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10648 const Id: func(number): number = (num: number): number => {
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10649 # Return a ID
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10650 return num * 10
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10651 }
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10652 endclass
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10653 var id = IdClass1.new()
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10654 assert_equal(20, id.Id(2))
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10655 END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10656 v9.CheckScriptSuccess(lines)
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10657
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10658 # This used to crash Vim
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10659 lines =<< trim END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10660 vim9script
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10661 class IdClass2
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10662 static const Id: func(number): number = (num: number): number => {
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10663 # Return a ID
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10664 return num * 2
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10665 }
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10666 endclass
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10667 assert_equal(16, IdClass2.Id(8))
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10668 END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10669 v9.CheckScriptSuccess(lines)
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10670 enddef
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10671
34834
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10672 " Test for defcompiling an abstract method
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10673 def Test_abstract_method_defcompile()
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10674 # Compile an abstract class with abstract object methods
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10675 var lines =<< trim END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10676 vim9script
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10677 abstract class A
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10678 abstract def Foo(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10679 abstract def Bar(): list<string>
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10680 endclass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10681 defcompile
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10682 END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10683 v9.CheckScriptSuccess(lines)
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10684
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10685 # Compile a concrete object method in an abstract class
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10686 lines =<< trim END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10687 vim9script
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10688 abstract class A
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10689 abstract def Foo(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10690 abstract def Bar(): list<string>
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10691 def Baz(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10692 pass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10693 enddef
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10694 endclass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10695 defcompile
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10696 END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10697 v9.CheckScriptFailure(lines, 'E476: Invalid command: pass', 1)
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10698
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10699 # Compile a concrete class method in an abstract class
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10700 lines =<< trim END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10701 vim9script
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10702 abstract class A
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10703 abstract def Foo(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10704 abstract def Bar(): list<string>
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10705 static def Baz(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10706 pass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10707 enddef
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10708 endclass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10709 defcompile
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10710 END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10711 v9.CheckScriptFailure(lines, 'E476: Invalid command: pass', 1)
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10712 enddef
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10713
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10714 " Test for defining a class in a function
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10715 def Test_class_definition_in_a_function()
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10716 var lines =<< trim END
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10717 vim9script
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10718 def Foo()
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10719 class A
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10720 endclass
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10721 enddef
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10722 defcompile
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10723 END
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10724 v9.CheckScriptFailure(lines, 'E1429: Class can only be used in a script', 1)
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10725 enddef
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10726
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
10727 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker