annotate src/testdir/test_vim9_class.vim @ 33393:016d8f863230 v9.0.1955

patch 9.0.1955: Vim9: lockvar issues with objects/classes Commit: https://github.com/vim/vim/commit/ee865f37acab6cac2cee6a171d60e1b365f852b0 Author: Ernie Rael <errael@raelity.com> Date: Fri Sep 29 19:53:55 2023 +0200 patch 9.0.1955: Vim9: lockvar issues with objects/classes Problem: Vim9: lockvar issues with objects/classes Solution: fix `get_lhs()` object/class access and avoid `SEGV`, make error messages more accurate. - `get_lval()` detects/returns object/class access - `compile_lock_unlock()` generate code for bare static and obj_arg access - `do_lock_var()` check lval for `ll_object`/`ll_class` and fail if so. Details: - Add `ll_object`/`ll_class`/`ll_oi` to `lval_T`. - Add `lockunlock_T` to `isn_T` for `is_arg` to specify handling of `lval_root` in `get_lval()`. - In `get_lval()`, fill in `ll_object`/`ll_class`/`ll_oi` as needed; when no `[idx] or .key`, check lval_root on the way out. - In `do_lock_var()` check for `ll_object`/`ll_class`; also bullet proof ll_dict case and give `Dictionay required` if problem. (not needed to avoid lockvar crash anymore) - In `compile_lock_unlock()` compile for the class variable and func arg cases. closes: #13174 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Ernie Rael <errael@raelity.com>
author Christian Brabandt <cb@256bit.org>
date Fri, 29 Sep 2023 20:00:07 +0200
parents b5ad84fdc702
children bb99820510ef
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
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
38 # Only the completed 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
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
70 # Use "this" without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
71 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
72 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
73 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
74 this
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
75 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
76 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
77 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
78
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
79 # Use "this." without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
80 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
81 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
82 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
83 this.
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
84 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
85 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
86 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this.', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
87
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
88 # Space between "this" and ".<variable>"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
89 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
90 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
91 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
92 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
93 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
94 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
95 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this .count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
96
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
97 # Space between "this." and the member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
98 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
99 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
100 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
101 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
102 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
103 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
104 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this. count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
105
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
106 # Use "that" instead of "this"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
107 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
108 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
109 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
110 this.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
111 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
112 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
113 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
114 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
115
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
116 # Member variable without a type or initialization
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
117 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
118 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
119 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
120 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
121 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
122 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
123 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
124
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
125 # Use a non-existing member variable in new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
126 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
127 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
128 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
129 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
130 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
131 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
132 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
133 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
134 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
135 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "Something": state', 1)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
136
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
137 # Space before ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
138 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
139 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
140 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
141 this.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
142 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
143 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
144 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
145
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
146 # No space after ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
147 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
148 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
149 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
150 this.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
151 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
152 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
153 v9.CheckSourceFailure(lines, "E1069: White space required after ':'", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
154
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
155 # 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
156 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
157 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
158 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
159 # 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
160 #{
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
161 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
162 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 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
164
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
165 # 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
166 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
167 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
168 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
169 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
170 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
171 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
172 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
173 v9.CheckSourceFailure(lines, 'E1319: Using a class as a Number', 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
174
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
175 # 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
176 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
177 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
178 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
179 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
180 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
181 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
182 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
183 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
184 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
185
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
186 # 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
187 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
188 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
189 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
190 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
191 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
192 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
193 v9.CheckSourceFailure(lines, 'E1321: Using a class as a Float', 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
194
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
195 # 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
196 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
197 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
198 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
199 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
200 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
201 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
202 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
203 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
204
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
205 # 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
206 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
207 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
208 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
209 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
210 :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
211 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
212 v9.CheckSourceFailure(lines, 'E1323: Using a class as a String', 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
213
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
214 # 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
215 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
216 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
217 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
218 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
219 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
220 :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
221 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
222 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
223
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
224 # 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
225 # 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
226 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
227 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
228
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
229 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
230 this.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
231 this.col: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
232
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
233 # 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
234 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
235 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
236 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
237 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
238
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
239 # 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
240 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
241 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
242 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
243
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
244 # 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
245 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
246
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
247 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
248 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
249 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
250 assert_equal('object<TextPosition>', typename(pos))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
251 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
252 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
253
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
254 # 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265 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
266
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
267 # 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
268 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
269 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
270 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
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 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
279
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
280 # 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
281 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
282 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
283 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
284 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
285 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
286 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
287 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
288 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
289 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
290 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
291
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
292 # 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
293 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
294 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
295 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
296 this.y = {
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
297 X: 1
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
298 }
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
299 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
300 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
301 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
302 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
303 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
304
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
305 " 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
306 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
307 # 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
308 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
309 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
310 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
311 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
312 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
313 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
314 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
315 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "this" or "static"', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
316
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
317 # 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
318 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
319 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
320 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
321 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
322 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
323 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
324 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
325 v9.CheckSourceFailure(lines, 'E1388: Public keyword not supported for a method', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
326
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
327 # Using the "public" keyword when defining an object private method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
328 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
329 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
330 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
331 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
332 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
333 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
334 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
335 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "this" or "static"', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
336
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
337 # Using the "public" keyword when defining a class private method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
338 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
339 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
340 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
341 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
342 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
343 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
344 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
345 v9.CheckSourceFailure(lines, 'E1388: Public keyword not supported for a method', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
346
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
347 # 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
348 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
349 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
350 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
351 def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
352 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
353 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
354 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
355 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
356
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
357 # 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
358 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
359 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
360 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
361 static def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
362 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
363 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
364 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
365 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
366 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
367
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
368 def Test_class_defined_twice()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
369 # class defined twice should fail
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
370 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
371 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
372 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
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 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
375 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
376 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
377 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "There"', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
378
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
379 # one class, reload same script twice is OK
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
380 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
381 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
382 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
383 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
384 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
385 writefile(lines, 'XclassTwice.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
386 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
387 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
388 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
389
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
390 def Test_returning_null_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
391 # this was causing an internal error
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
392 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
393 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
394
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
395 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
396 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
397 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
398 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
399 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
400
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
401 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
402 echo buffers.Current()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
403 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
404 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
405 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
406
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
407 def Test_using_null_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
408 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
409 @_ = 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
410 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
411 v9.CheckDefExecAndScriptFailure(lines, ['E715: Dictionary required', 'E1363: Incomplete type'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
412 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
413
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
414 def Test_class_interface_wrong_end()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
415 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
416 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
417 abstract class SomeName
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
418 this.member = 'text'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
419 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
420 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
421 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
422
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
423 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
424 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
425 export interface AnotherName
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
426 this.member: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
427 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
428 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
429 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
430 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
431
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
432 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
433 # Use an uninitialized object in script context
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
434 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
435 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
436
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
437 class State
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
438 this.value = 'xyz'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
439 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
440
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
441 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
442 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
443 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
444 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
445 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 9)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
446
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
447 # Use an uninitialized object from a def function
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
448 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
449 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
450
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
451 class Class
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
452 this.id: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
453 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
454 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
455 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
456 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
457
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
458 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
459 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
460 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
461 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
462 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
463 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
464 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
465
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
466 # 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
467 # object method.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
468 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
469 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
470
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
471 class Background
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
472 this.background = 'dark'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
473 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
474
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
475 class Colorscheme
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
476 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
477
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
478 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
479 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
480 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
481 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
482
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
483 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
484 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
485 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
486 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
487
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
488 # 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
489 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
490 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
491
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
492 class Class
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
493 this.id: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
494 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
495 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
496 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
497 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
498
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
499 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
500 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
501 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
502 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
503 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
504 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
505 v9.CheckSourceFailure(lines, 'E1363: Incomplete type', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
506 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
507
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
508 " 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
509 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
510 var lines =<< trim END
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
511 vim9script
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
512
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
513 var nullo = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
514 def F(): any
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
515 return nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
516 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
517 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
518
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
519 var o0 = F()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
520 assert_true(o0 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
521 assert_true(o0 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
522
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
523 var o1: any = nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
524 assert_true(o1 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
525 assert_true(o1 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
526
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
527 def G()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
528 var x = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
529 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
530
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
531 class C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
532 endclass
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
533 var o2: C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
534 assert_true(o2 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
535 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
536
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
537 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
538 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
539
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
540 o2 = C.new()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
541 assert_true(o2 != null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
542
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
543 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
544 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
545 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
546 v9.CheckSourceSuccess(lines)
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
547 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
548
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
549 " Test for object member initialization and disassembly
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
550 def Test_class_member_initializer()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
551 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
552 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
553
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
554 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
555 this.lnum: 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
556 this.col: 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
557
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
558 # 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
559 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
560 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
561 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
562 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
563
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
564 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
565 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
566 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
567
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
568 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
569 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
570 '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
571 '\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
572 '\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
573 '\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
574 '\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
575 '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
576 '\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
577 '\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
578 '\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
579 '\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
580 '\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
581 instr)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
582 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
583 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
584 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
585
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
586 def Test_member_any_used_as_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
587 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
588 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
589
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
590 class Inner
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
591 this.value: number = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
592 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
593
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
594 class Outer
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
595 this.inner: any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
596 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
597
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
598 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
599 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
600 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
601
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
602 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
603 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
604 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
605 assert_equal(1, inner_obj.value)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
606 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
607 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
608
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
609 # Try modifying a private 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
610 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
611 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
612
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
613 class Inner
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
614 this._value: string = ''
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
615 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
616
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
617 class Outer
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
618 this.inner: any
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
619 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
620
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
621 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
622 outer.inner._value = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
623 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
624
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
625 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
626 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
627 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
628 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
629 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable: _value', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
630
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
631 # 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
632 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
633 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
634
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
635 class Inner
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
636 this.value: string = ''
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
637 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
638
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
639 class Outer
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
640 this.inner: any
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
641 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
642
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
643 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
644 outer.inner.someval = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
645 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
646
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
647 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
648 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
649 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
650 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
651 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "Inner": someval', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
652 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
653
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
654 " 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
655 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
656 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
657 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
658
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
659 class Inner
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
660 public this.value: number = 0
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
661 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
662
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
663 class Outer
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
664 this.inner: Inner
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
665 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
666
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
667 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
668 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
669 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
670
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
671 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
672 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
673 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
674 F(outer)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
675 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
676 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
677
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
678 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
679
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
680 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
681 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
682 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
683 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
684 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
685 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
686
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
687 # 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
688 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
689 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
690
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
691 class Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
692 this.value: number = 0
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
693 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
694
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
695 class Outer
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
696 this.inner: Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
697 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
698
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
699 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
700 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
701 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
702
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
703 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
704 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
705 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
706 F(outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
707 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
708 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
709
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
710 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
711 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
712 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
713
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
714 # 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
715 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
716 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
717
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
718 class Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
719 this.value: number = 0
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
720 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
721
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
722 class Outer
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
723 this.inner: Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
724 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
725
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
726 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
727 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
728 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
729
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
730 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
731 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
732 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
733 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
734 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
735 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
736 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
737
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
738 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
739 # Use "+=" to assign to a object variable
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
740 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
741 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
742
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
743 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
744 public this.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
745
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
746 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
747 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
748 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
749 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
750
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
751 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
752 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
753 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
754
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
755 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
756 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
757 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
758
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
759 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
760 assert_equal(23, f.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
761 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
762 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
763 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
764
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
765 def Test_list_of_objects()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
766 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
767 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
768
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
769 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
770 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
771 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
772 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
773
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
774 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
775 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
776 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
777 endfor
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
778 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
779
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
780 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
781 ProcessList(l)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
782 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
783 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
784 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
785
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
786 def Test_expr_after_using_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
787 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
788 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
789
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
790 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
791 this.label: string = ''
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
792 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
793
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
794 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
795 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
796 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
797 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
798 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
799
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
800 Foo()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
801 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
802 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
803 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
804
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
805 def Test_class_default_new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
806 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
807 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
808
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
809 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
810 this.lnum: 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
811 this.col: 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
812 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
813
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
814 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
815 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
816 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
817
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
818 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
819 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
820 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
821
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
822 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
823 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
824 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
825
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
826 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
827 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
828 assert_equal(33, pos.col)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
829 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
830 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
831
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
832 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
833 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
834 class Person
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
835 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
836 this.age: number = 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
837 this.education: string = "unknown"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
838
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
839 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
840 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
841 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
842
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
843 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
844 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
845 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
846 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
847
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
848 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
849 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
850 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
851 assert_equal("none", chris.education)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
852 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
853 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
854
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
855 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
856 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
857 class Person
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
858 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
859 this.age: number = 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
860 this.education: string = "unknown"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
861
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
862 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
863 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
864 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
865
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
866 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
867 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
868 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
869
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
870 # 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
871 # method.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
872 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
873 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
874 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
875 this.val: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
876 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
877 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
878 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
879 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
880 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
881 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
882
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
883 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
884 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
885 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
886
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
887 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
888 this.str: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
889 this.num: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
890 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
891 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
892 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
893 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
894 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
895
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
896 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
897 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
898 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
899 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
900 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
901
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
902 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
903 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
904 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
905 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
906 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
907 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
908 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
909
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
910 Check()
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
911 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
912 v9.CheckSourceSuccess(lines)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
913
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
914 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
915 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
916
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
917 class C
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
918 this.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
919 this.num: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
920 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
921 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
922 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
923
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
924 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
925 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
926 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
927 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
928 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
929 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
930 enddef
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 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
933 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
934 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
935
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
936 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
937 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
938
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
939 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
940 this.str: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
941 this.num: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
942 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
943 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
944 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
945
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
946 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
947 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
948 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
949 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
950 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
951 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
952 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
953
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
954 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
955 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
956 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
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 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
959 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
960
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
961 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
962 this.str: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
963 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
964 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
965 endclass
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 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
968 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
969 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
970 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
971 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
972 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
973 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
974
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
975 Check()
33326
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
976 END
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
977 v9.CheckSourceSuccess(lines)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
978 enddef
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
979
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
980 def Test_class_object_member_inits()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
981 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
982 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
983 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
984 this.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
985 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
986 this.addcol: 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
987 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
988
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
989 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
990 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
991 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
992 assert_equal(2, pos.addcol)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
993 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
994 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
995
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
996 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
997 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
998 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
999 this.lnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1000 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1001 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1002 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1003 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1004
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1005 # 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
1006 # object creation and not when defining the class.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1007 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
1008 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1009
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1010 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
1011 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
1012 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
1013 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
1014 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1015
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1016 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1017 this.str1 = Init()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1018 this.str2: string = Init()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1019 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1020 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1021
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1022 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
1023 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
1024 assert_equal(init_count, 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1025 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1026 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
1027
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1028 # 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
1029 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
1030 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
1031 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
1032 this.value = init_val
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1033 endclass
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1034 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
1035 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
1036 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
1037
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1038 # 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
1039 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
1040 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1041 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
1042 this.value: void
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1043 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1044 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
1045 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
1046 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1047
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1048 " 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
1049 def Test_instance_variable_access()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1050 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
1051 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1052 class Triple
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1053 this._one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1054 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1055 public this.three = 3
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1056
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1057 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
1058 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
1059 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1060 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1061
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1062 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
1063 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
1064 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
1065 assert_equal(3, 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
1066 assert_fails('echo trip._one', 'E1333: Cannot access private variable: _one')
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 assert_fails('trip._one = 11', 'E1333: Cannot access private variable: _one')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1069 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
1070 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
1071 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
1072
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1073 assert_fails('trip.four = 4', 'E1326: Variable not found on object "Triple": four')
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1074 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1075 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1076
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
1077 # 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
1078 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
1079 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
1080 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
1081 public this._val = 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
1082 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
1083 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
1084 v9.CheckSourceFailure(lines, 'E1332: Public variable name cannot start with underscore: public this._val = 10', 3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1085
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1086 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
1087 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1088
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1089 class MyCar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1090 this.make: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1091 this.age = 5
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1092
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1093 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
1094 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
1095 enddef
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 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
1098 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
1099 enddef
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 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
1101 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
1102 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1103 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1104
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1105 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
1106 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
1107
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1108 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
1109 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
1110
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1111 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
1112 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
1113
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1114 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
1115 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
1116 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
1117 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1118 CheckCar()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1119 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1120 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1121
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1122 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
1123 vim9script
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 class MyCar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1126 this.make: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1127
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1128 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
1129 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
1130 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1131 endclass
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 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
1134 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
1135 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1136 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
1137
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1138 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
1139 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1140
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1141 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
1142 this.x: list<number> = []
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1143
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1144 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
1145 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
1146 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
1147 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1148 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1149
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1150 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
1151 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
1152 .x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1153 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
1154 .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
1155 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
1156 .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
1157 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
1158 .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
1159 .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
1160 .x
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1161 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1162 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
1163
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1164 # 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
1165 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
1166 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
1167 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
1168 pub this.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
1169 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
1170 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
1171 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: pub this.val = 1', 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
1172
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1173 # Test for "public" keyword must be followed by "this" or "static".
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1174 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
1175 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
1176 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
1177 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
1178 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
1179 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
1180 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "this" or "static"', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1181
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1182 # 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
1183 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1184 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1185 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1186 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1187 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1188 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1189 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
1190 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
1191
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1192 # 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
1193 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
1194 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1195 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1196 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1197 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1198 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1199 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
1200 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
1201
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1202 # 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
1203 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
1204 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1205 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1206 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1207 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1208 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1209 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1210 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1211 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1212 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
1213 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
1214
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1215 # 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
1216 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1217 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1218 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1219 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1220 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1221 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1222 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1223 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1224 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1225 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
1226 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
1227
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1228 # 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
1229 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
1230 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1231 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1232 this.ro_obj_var = 10
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1233 public this.rw_obj_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
1234 this._priv_obj_var = 30
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1235 endclass
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 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
1238 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
1239 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
1240 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
1241 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
1242 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
1243 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
1244 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
1245 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
1246 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1247 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1248
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1249 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
1250 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1251 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1252 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1253 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1254
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1255 " 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
1256 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
1257 # 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
1258 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1259 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1260 class Something
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1261 stat this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1262 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1263 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
1264 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: stat this.val = 1', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1265
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1266 # Test for "static" cannot be followed by "this".
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1267 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1268 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1269 class Something
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1270 static this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1271 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1272 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
1273 v9.CheckSourceFailure(lines, 'E1368: Static cannot be followed by "this" in a variable name', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1274
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1275 # 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
1276 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1277 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1278 class Something
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1279 static public val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1280 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1281 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
1282 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1283
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1284 # 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
1285 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
1286 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1287 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1288 static ro_class_var = 40
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1289 endclass
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 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
1292 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
1293 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
1294 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1295 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1296
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1297 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
1298 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
1299 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1300 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
1301
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1302 # A private class variable cannot be accessed from a child class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1303 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
1304 vim9script
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 A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1306 static _priv_class_var = 60
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1307 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1308
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1309 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
1310 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
1311 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
1312 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1313 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1314
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1315 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
1316 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
1317 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1318 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable: _priv_class_var', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1319
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1320 # A private 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
1321 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
1322 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1323 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1324 static _priv_class_var = 60
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1325 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1326
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1327 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
1328 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
1329 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
1330 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1331 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1332
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1333 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
1334 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
1335 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1336 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable: _priv_class_var', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1337
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1338 # 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
1339 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
1340 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1341 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1342 static ro_class_var = 10
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1343 public static 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
1344 static _priv_class_var = 30
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1345 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1346
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1347 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
1348 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
1349 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
1350 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
1351 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
1352 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
1353 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
1354 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
1355 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
1356 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1357 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1358
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1359 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
1360 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
1361 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
1362 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
1363 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
1364 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1365 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1366 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1367 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1368
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1369 def Test_class_object_compare()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1370 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
1371 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1372 class Item
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1373 this.nr = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1374 this.name = 'xx'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1375 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1376 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1377
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1378 # used at the script level and in a compiled function
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1379 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
1380 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
1381 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
1382 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
1383 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
1384 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
1385 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
1386 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
1387 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
1388
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1389 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
1390 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
1391 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
1392 assert_notequal(i1, io2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1393 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1394
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1395 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
1396 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
1397 class_lines + ['def Test()'] + test_lines + ['enddef', 'Test()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1398
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1399 for op in ['>', '>=', '<', '<=', '=~', '!~']
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1400 var op_lines = [
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1401 'var i1 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1402 'var i2 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1403 'echo i1 ' .. op .. ' i2',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1404 ]
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1405 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
1406 v9.CheckSourceFailure(class_lines
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1407 + ['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
1408 endfor
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1409 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1410
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1411 def Test_object_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1412 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
1413 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1414
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1415 class One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1416 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1417 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1418 class Two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1419 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1420 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1421 class TwoMore extends Two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1422 this.more = 9
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1423 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1424
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1425 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
1426 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
1427 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
1428 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
1429
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1430 t = m
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1431 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1432 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1433
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1434 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
1435 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1436
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1437 class One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1438 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1439 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1440 class Two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1441 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1442 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1443
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1444 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
1445 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1446 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
1447
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1448 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
1449 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1450
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1451 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
1452 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
1453 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1454 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
1455 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1456 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
1457 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
1458 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1459 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1460
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1461 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
1462 assert_equal(5, o.GetMember())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1463 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1464 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1465
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1466 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
1467 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1468
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1469 class Num
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1470 this.n: number = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1471 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1472
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1473 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
1474 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
1475 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
1476 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1477 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1478
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1479 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
1480 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
1481
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1482 echo Fn(Num.new(4))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1483 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1484 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1485 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1486
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1487 def Test_class_member()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1488 # check access rules
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1489 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
1490 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1491 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
1492 this.lnum = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1493 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1494 static counter = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1495 static _secret = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1496 public static anybody = 42
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 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
1499 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
1500 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1501 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1502
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1503 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
1504 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
1505 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
1506 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
1507
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1508 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
1509 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
1510 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1511 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
1512
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1513 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
1514 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
1515 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
1516
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1517 assert_fails('echo TextPos._secret', 'E1333: Cannot access private variable: _secret')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1518 assert_fails('TextPos._secret = 8', 'E1333: Cannot access private variable: _secret')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1519
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1520 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
1521 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
1522 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
1523 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
1524 assert_equal(17, TextPos.anybody)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1525 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1526 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1527
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1528 # example in the help
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1529 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
1530 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1531 class OtherThing
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1532 this.size: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1533 static totalSize: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1534
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1535 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
1536 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
1537 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1538 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1539 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
1540 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
1541 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
1542 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
1543 assert_equal(10, OtherThing.totalSize)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1544 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1545 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1546
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1547 # using static class member twice
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1548 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
1549 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1550
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1551 class HTML
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1552 static author: string = 'John Doe'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1553
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1554 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
1555 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
1556 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1557 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1558
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1559 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
1560 assert_equal('some text', HTML.MacroSubstitute('some text'))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1561 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1562 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1563
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1564 # access private member in lambda
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1565 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
1566 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1567
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 Foo
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1569 this._x: number = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1570
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1571 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
1572 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
1573 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
1574 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1575 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1576
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1577 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
1578 assert_equal(5, foo.Add(5))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1579 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1580 v9.CheckSourceSuccess(lines)
32670
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 # access private member in lambda body
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1583 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 Foo
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1587 this._x: number = 6
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1588
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1589 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
1590 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
1591 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
1592 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1593 Lam()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1594 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
1595 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1596 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1597
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 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
1599 assert_equal(13, foo.Add(7))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1600 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1601 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1602
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1603 # check shadowing
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1604 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
1605 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1606
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1607 class Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1608 static 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
1609 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
1610 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
1611 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1612 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1613
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1614 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
1615 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
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, 'E1340: Argument already declared in the class: count', 5)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1618
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
1619 # 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
1620 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
1621 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1622
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1623 class Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1624 static 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
1625 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
1626 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
1627 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
1628 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1629 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1630
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1631 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
1632 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
1633 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1634 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
1635
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1636 # 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
1637 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
1638 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
1639 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
1640 this.val: xxx
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1641 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
1642 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
1643 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
1644
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1645 # 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
1646 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1647 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1648 class 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
1649 public this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1650 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1651
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1652 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
1653 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
1654 obj.val = ""
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1655 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1656 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1657 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
1658 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
1659
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1660 # 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
1661 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1662 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1663 class 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
1664 this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1665 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1666
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1667 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
1668 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
1669 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
1670 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1671 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1672 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
1673 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
1674
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1675 # 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
1676 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1677 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1678 class 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
1679 public this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1680 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1681
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1682 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1683 obj.val = ""
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1684 END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1685 # FIXME(in source): this should give E1360 as well!
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1686 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected object<A> but got string', 7)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1687
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1688 # 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
1689 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1690 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1691 class 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
1692 this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1693 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1694
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1695 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1696 echo obj.val
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1697 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
1698 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
1699
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
1700 # 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
1701 # 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
1702 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
1703 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
1704 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
1705 this.val: 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
1706 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
1707 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
1708 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
1709 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
1710 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
1711 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
1712 this.val: 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
1713 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
1714 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
1715 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
1716
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1717 # 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
1718 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
1719 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
1720 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
1721 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
1722 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
1723 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
1724 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
1725 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "A": bar', 5)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1726 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1727
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1728 func Test_class_garbagecollect()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1729 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
1730 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1731
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1732 class Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1733 this.p = [2, 3]
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1734 static pl = ['a', 'b']
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1735 static pd = {a: 'a', b: 'b'}
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1736 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1737
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1738 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
1739 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
1740 echo Point.pl Point.pd
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1741 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1742 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1743
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1744 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
1745 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1746
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1747 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
1748 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1749
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1750 class Widget
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1751 this.view: View
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1752 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1753
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1754 class MyView implements View
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1755 this.widget: Widget
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 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
1758 # this will result in a circular reference to this object
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1759 this.widget = Widget.new(this)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1760 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1761 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1762
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1763 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
1764
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1765 # 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
1766 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
1767 test_garbagecollect_now()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1768 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1769 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1770 endfunc
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1771
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1772 " Test interface garbage collection
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1773 func Test_interface_garbagecollect()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1774 let lines =<< trim END
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1775 vim9script
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1776
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1777 interface I
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1778 this.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
1779
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1780 def ObjFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1781 endinterface
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1782
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1783 class A implements I
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1784 static ro_class_var: number = 10
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1785 public static rw_class_var: number = 20
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1786 static _priv_class_var: number = 30
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1787 this.ro_obj_var: number = 40
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1788 this._priv_obj_var: number = 60
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1789
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1790 static def _ClassBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1791 return _priv_class_var
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1792 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1793
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1794 static def ClassFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1795 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
1796 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1797
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1798 def _ObjBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1799 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
1800 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1801
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1802 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
1803 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
1804 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1805 endclass
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1806
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1807 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
1808 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
1809 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
1810 test_garbagecollect_now()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1811 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
1812 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
1813 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1814 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
1815 endfunc
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1816
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1817 def Test_class_method()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1818 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
1819 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1820 class Value
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1821 this.value = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1822 static objects = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1823
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1824 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
1825 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
1826 ++objects
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1827 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1828
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1829 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
1830 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
1831 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1832 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1833
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1834 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
1835 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
1836 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
1837 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
1838 assert_equal(2, Value.GetCount())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1839 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1840 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
1841
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1842 # 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
1843 # 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
1844 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
1845 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
1846 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
1847 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
1848 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
1849 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
1850 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
1851 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
1852 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
1853
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1854 # 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
1855 # name prefix.
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1856 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
1857 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1858 class A
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1859 static myList: list<number> = [1]
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1860 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
1861 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
1862 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1863 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
1864 Foo(2)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1865 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1866 def Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1867 Foo(3)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1868 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1869 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1870 A.Bar()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1871 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
1872 a.Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1873 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
1874 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1875 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1876 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1877
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1878 def Test_class_defcompile()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1879 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
1880 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1881
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1882 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
1883 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
1884 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
1885 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1886 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1887
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1888 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
1889 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1890 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
1891
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1892 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
1893 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1894
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1895 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
1896 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
1897 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
1898 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1899 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1900
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1901 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
1902 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1903 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
1904
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1905 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
1906 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1907
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1908 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
1909 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
1910 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1911 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1912
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1913 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
1914 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1915 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
1916
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
1917 # 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
1918 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
1919 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
1920 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
1921 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
1922 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
1923
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1924 # 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
1925 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
1926 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
1927 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
1928 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
1929 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
1930 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
1931
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1932 # 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
1933 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
1934 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
1935 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
1936 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
1937 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
1938 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
1939 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
1940
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1941 # 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
1942 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
1943 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
1944 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
1945 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
1946 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
1947 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
1948 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
1949 v9.CheckSourceFailureList(lines, ['E1326: Variable not found on object "A": Foo', 'E475: Invalid argument: a.Foo()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1950 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1951
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1952 def Test_class_object_to_string()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1953 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
1954 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1955 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1956 this.lnum = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1957 this.col = 22
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1958 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1959
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1960 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
1961
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1962 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
1963 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
1964 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1965 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1966 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1967
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1968 def Test_interface_basics()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1969 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
1970 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1971 interface Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1972 this.ro_var: list<number>
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1973 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
1974 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1975 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1976 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1977
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1978 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
1979 interface SomethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1980 static count = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1981 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1982 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1983 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
1984
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1985 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
1986 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1987
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1988 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1989 this.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
1990 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
1991 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1992 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1993 # 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
1994 # 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
1995 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1996
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1997 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
1998 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1999 interface somethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2000 static count = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2001 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2002 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2003 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
2004
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2005 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
2006 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2007 interface SomethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2008 this.value: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2009 this.count = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2010 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
2011 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2012 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2013 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
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 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
2016 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2017 interface SomethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2018 this.value: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2019 this.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
2020 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
2021 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
2022 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2023 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2024 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2025 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
2026
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2027 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
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 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
2030 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
2031 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
2032 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2033 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2034 writefile(lines, 'XdefIntf.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2035
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2036 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
2037 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2038 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
2039 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
2040 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
2041 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2042 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2043 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2044 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
2045 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2046 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2047 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2048 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2049
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2050 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
2051 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2052 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
2053 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
2054 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2055 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
2056 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2057 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2058 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2059 writefile(imported, 'XdefIntf2.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2060
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2061 lines[1] = " import './XdefIntf2.vim' as defIntf"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2062 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2063 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2064
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2065 def Test_class_implements_interface()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2066 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
2067 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2068
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2069 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2070 this.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
2071 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
2072 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2073
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2074 class SomeImpl implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2075 this.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
2076 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
2077 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
2078 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2079 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2080
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2081 interface Another
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2082 this.member: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2083 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2084
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2085 class AnotherImpl implements Some, Another
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2086 this.member = 'abc'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2087 this.count = 20
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2088 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
2089 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
2090 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2091 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2092 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2093 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2094
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2095 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
2096 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2097
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2098 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2099 this.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
2100 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2101
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2102 class SomeImpl implements Some implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2103 this.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
2104 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2105 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2106 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
2107
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2108 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
2109 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2110
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2111 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2112 this.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
2113 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2114
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2115 class SomeImpl implements Some, Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2116 this.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
2117 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2118 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2119 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
2120
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2121 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
2122 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2123
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2124 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2125 this.counter: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2126 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
2127 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2128
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2129 class SomeImpl implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2130 this.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
2131 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
2132 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
2133 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2134 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2135 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2136 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
2137
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2138 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
2139 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2140
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2141 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2142 this.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
2143 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
2144 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2145
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2146 class SomeImpl implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2147 this.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
2148 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
2149 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
2150 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2151 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2152 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2153 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
2154
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2155 # Check different order of members in class and interface works.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2156 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
2157 vim9script
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2158
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2159 interface Result
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2160 this.label: string
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2161 this.errpos: number
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2162 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2163
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2164 # order of members is opposite of interface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2165 class Failure implements Result
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2166 public this.lnum: number = 5
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2167 this.errpos: number = 42
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2168 this.label: string = 'label'
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2169 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2170
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2171 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
2172 var result: Result = Failure.new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2173
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2174 assert_equal('label', result.label)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2175 assert_equal(42, result.errpos)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2176 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2177
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2178 Test()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2179 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2180 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
2181
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2182 # 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
2183 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
2184 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
2185 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
2186 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
2187 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
2188 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
2189 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
2190 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
2191
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2192 # 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
2193 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
2194 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
2195 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
2196 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
2197 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
2198 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
2199
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 # 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
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 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
2204 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
2205 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
2206 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
2207
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 # 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
2209 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
2210 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
2211 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
2212 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
2213 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
2214 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
2215 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
2216 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
2217
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 # 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
2219 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
2220 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
2221 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
2222 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
2223 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
2224 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
2225 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
2226
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2227 # 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
2228 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2229 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2230 interface A
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2231 endinterface
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2232 class B implements A;
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2233 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2234 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
2235 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
2236
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2237 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
2238 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2239
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2240 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
2241 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
2242 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2243 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
2244 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
2245 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2246 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2247 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2248 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
2249
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2250 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
2251 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2252
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2253 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
2254 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
2255 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2256 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
2257 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
2258 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2259 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2260 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2261 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
2262
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2263 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
2264 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2265
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2266 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
2267 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
2268 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2269 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
2270 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
2271 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2272 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2273 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2274 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
2275
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2276 # 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
2277 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2278 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2279
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2280 interface I1
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 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2282 this.mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2283 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2284
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2285 # 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
2286 class A implements I1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2287 this.mvar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2288 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2289 public static svar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2290 public static svar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2291 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
2292 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
2293 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
2294 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
2295 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
2296 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2297 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2298
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2299 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
2300 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
2301 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
2302 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
2303 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2304 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2305
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2306 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
2307 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
2308 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
2309 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
2310 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2311 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2312
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2313 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
2314 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
2315 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2316
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2317 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2318 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2319 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2320
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2321 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
2322 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
2323 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
2324 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2325 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2326
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2327 # 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
2328 # 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
2329 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2330 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2331
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2332 interface I1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2333 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2334 this.mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2335 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2336
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2337 interface I2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2338 this.mvar3: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2339 this.mvar4: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2340 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2341
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2342 class A implements I1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2343 public static svar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2344 public static svar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2345 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2346 this.mvar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2347 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
2348 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
2349 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
2350 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
2351 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
2352 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2353 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2354
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2355 class B extends A implements I2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2356 static svar3: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2357 static svar4: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2358 this.mvar3: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2359 this.mvar4: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2360 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
2361 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
2362 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
2363 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
2364 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
2365 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
2366 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
2367 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2368 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2369
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2370 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
2371 public static svar5: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2372 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
2373 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
2374 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
2375 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
2376 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
2377 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
2378 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2379 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2380
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2381 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
2382 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
2383 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2384
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2385 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
2386 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
2387 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2388
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2389 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2390 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2391 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2392
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2393 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
2394 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
2395 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
2396 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2397 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
2398
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2399 # 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
2400 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
2401 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2402 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2403 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2404 interface B
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2405 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2406 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
2407 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2408 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2409 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
2410
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2411 # 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
2412 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
2413 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2414 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2415 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2416 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
2417 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2418 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2419 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
2420
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2421 # 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
2422 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
2423 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2424 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
2425 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2426 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2427 v9.CheckSourceFailure(lines, 'E1389: Missing name after implements', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2428 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2429
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2430 def Test_call_interface_method()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2431 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2432 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2433 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2434 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2435 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2436
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2437 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2438 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2439 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2440 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2441 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2442
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2443 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2444 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2445 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2446
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2447 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2448 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2449 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2450 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2451 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2452 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2453
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2454 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2455 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2456 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2457 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2458 g:result ..= 'base'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2459 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2460 endclass
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 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2463 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2464 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2465 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2466 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2467
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2468 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2469 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2470 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2471
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2472 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2473 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2474 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2475 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2476 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2477 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2478
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2479 # method of interface returns a value
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2480 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2481 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2482 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2483 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2484 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2485
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2486 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2487 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2488 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2489 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2490 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2491 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2492
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2493 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2494 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2495 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2496 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2497
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2498 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2499 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2500 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2501 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2502 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2503 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2504
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2505 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2506 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2507 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2508 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2509 return null_string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2510 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2511 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2512
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2513 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2514 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2515 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2516 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2517 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2518 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2519
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2520 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2521 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2522 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2523 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2524
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2525 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2526 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2527 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2528 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2529 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2530 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2531
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2532 # No class that implements the interface.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2533 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
2534 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2535
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2536 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
2537 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
2538 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
2539 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2540
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2541 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
2542 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
2543 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2544
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2545 defcompile
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2546 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2547 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2548 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2549
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2550 def Test_class_used_as_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2551 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
2552 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2553
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2554 class Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2555 this.x = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2556 this.y = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2557 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2558
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2559 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
2560 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
2561 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
2562 assert_equal(33, p.y)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2563 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2564 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2565
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2566 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
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 HasX
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2570 this.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
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2573 class Point implements HasX
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2574 this.x = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2575 this.y = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2576 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2577
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2578 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
2579 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
2580 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
2581 assert_equal(2, hx.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2582 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2583 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2584
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2585 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
2586 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2587
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2588 class Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2589 this.x = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2590 this.y = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2591 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2592
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2593 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
2594 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
2595 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2596 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
2597 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2598
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2599 def Test_class_extends()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2600 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
2601 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2602 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2603 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2604 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
2605 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
2606 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2607 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2608 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
2609 this.two = 2
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 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
2611 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
2612 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2613 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2614 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
2615 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
2616 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
2617 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
2618 assert_equal(3, o.GetTotal())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2619 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2620 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2621
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2622 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
2623 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2624 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2625 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2626 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2627 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
2628 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2629 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2630 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
2631 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
2632 assert_equal(44, o.two)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2633 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2634 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2635
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2636 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
2637 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2638 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2639 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2640 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2641 class Child extends Base 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
2642 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2643 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2644 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2645 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
2646
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2647 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
2648 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2649 class Child extends BaseClass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2650 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2651 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2652 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2653 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
2654
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2655 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
2656 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2657 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
2658 class Child extends SomeVar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2659 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2660 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2661 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2662 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
2663
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2664 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
2665 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2666 class Base
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.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2668 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
2669 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
2670 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2671 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2672
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2673 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
2674 this.age: number
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 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
2676 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
2677 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2678 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2679
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2680 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
2681 assert_equal('John: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2682 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2683 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2684
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2685 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
2686 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2687 class Child
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2688 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2689 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
2690 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
2691 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2692 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
2693 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
2694 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2695 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2696 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2697 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
2698
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2699 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
2700 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2701 class Child
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2702 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2703 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
2704 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
2705 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2706 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2707 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
2708 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
2709 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2710 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
2711
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2712 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
2713 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2714 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2715 this.name: string
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2716 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
2717 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
2718 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2719 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2720
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2721 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
2722 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
2723 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
2724 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2725 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
2726 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2727 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
2728
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2729 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
2730 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2731 class Child
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2732 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2733 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
2734 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
2735 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2736 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2737 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
2738 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
2739 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2740 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
2741
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2742 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
2743 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2744 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2745 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2746 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
2747 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
2748 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2749 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2750
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2751 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
2752 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2753 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
2754 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
2755 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2756 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2757
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2758 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
2759 assert_equal('Base class: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2760 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2761 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2762
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2763 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
2764 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2765 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2766 this.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
2767 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
2768 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
2769 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2770 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2771 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
2772 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
2773 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
2774 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2775 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2776 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
2777 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2778 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
2779
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2780 # base class with more than one object member
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2781 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
2782 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2783
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2784 class Result
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2785 this.success: bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2786 this.value: any = null
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2787 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2788
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2789 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
2790 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
2791 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
2792 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2793 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2794
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2795 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
2796 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
2797 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2798 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
2799
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2800 # 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
2801 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
2802 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
2803 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
2804 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
2805 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
2806 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
2807 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
2808 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
2809 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2810
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2811 def Test_using_base_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2812 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2813 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2814
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2815 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
2816 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
2817 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
2818 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2819 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
2820 enddef
32670
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 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
2824 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
2825 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
2826 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2827
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2828 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
2829 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
2830 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2831 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2832
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2833 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
2834 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
2835 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2836 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
2837 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2838 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
2839 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
2840 endtry
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2841 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2842
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2843 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2844 With(ChildEE.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2845 assert_equal('42/finally/exit', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2846 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2847 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2848 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2849
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2850 # 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
2851 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2852 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2853
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2854 class 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
2855 this.success: bool = false
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2856 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
2857 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
2858 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2859 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2860
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2861 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
2862 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
2863 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
2864 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2865 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2866
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2867 var obj = Child.new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2868 assert_equal(true, obj.success)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2869 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2870 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2871 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2872
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2873 def Test_class_import()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2874 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
2875 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2876 export class Animal
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2877 this.kind: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2878 this.name: string
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
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2880 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2881 writefile(lines, 'Xanimal.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2882
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2883 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
2884 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2885 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
2886
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2887 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
2888 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
2889 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
2890 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
2891
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2892 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
2893 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
2894 assert_equal('Garfield', b.name)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2895 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2896 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2897 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2898
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2899 def Test_abstract_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2900 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
2901 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2902 abstract class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2903 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2904 endclass
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 Person 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
2906 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2907 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2908 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
2909 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
2910 assert_equal(42, p.age)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2911 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2912 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2913
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2914 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
2915 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2916 abstract class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2917 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2918 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2919 class Person 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
2920 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2921 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2922 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
2923 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2924 v9.CheckSourceFailure(lines, 'E1325: Method not found on class "Base": new', 8)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2925
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2926 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
2927 abstract class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2928 this.name: string
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 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2931 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
2932
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2933 # 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
2934 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
2935 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
2936 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
2937 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
2938 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
2939 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
2940 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
2941 v9.CheckSourceFailure(lines, 'E1359: Cannot define a "new" method in an abstract class', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2942 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2943
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2944 def Test_closure_in_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2945 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
2946 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2947
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2948 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
2949 this.y: list<string> = ['B']
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2950
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2951 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
2952 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
2953 enddef
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2956 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
2957 assert_equal(['A'], g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2958 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2959 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2960 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2961
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2962 def Test_call_constructor_from_legacy()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2963 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
2964 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2965
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2966 var newCalled = 'false'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2967
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2968 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2969 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
2970 newCalled = 'true'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2971 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2972 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2973
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2974 export def F(options = {}): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2975 return A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2976 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2977
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2978 g:p = F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2979 legacy call p.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2980 assert_equal('true', newCalled)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2981 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2982 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2983 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2984
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2985 def Test_defer_with_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2986 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
2987 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2988
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2989 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
2990 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
2991 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
2992 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2993 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
2994 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
2995 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2996 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2997
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2998 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
2999 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
3000 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
3001 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3002 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3003
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3004 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
3005 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
3006 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
3007 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
3008 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3009 assert_equal('entered/called/exited', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3010 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3011 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3012 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3013
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3014 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
3015 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3016
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 BaseWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3018 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
3019 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
3020 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3021 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
3022 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
3023 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3024 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3025
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3026 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
3027 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
3028 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
3029 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3030 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
3031 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
3032 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3033 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3034
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3035 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
3036 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
3037 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
3038 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3039 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3040
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3041 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
3042 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
3043 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
3044 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
3045 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3046 assert_equal('entered-child/called/exited-child', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3047 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3048 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3049 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3050 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3051
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3052 " 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
3053 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
3054 var lines =<< trim END
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3055 vim9script
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3056
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3057 class Observer
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3058 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3059
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3060 class Property
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3061 this.value: any
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3062
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3063 def Set(v: any)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3064 if v != this.value
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3065 this.value = v
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3066 endif
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3067 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3068
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3069 def Register(observer: Observer)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3070 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3071 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3072
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3073 class Bool extends Property
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
3074 this.value2: bool
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3075 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3076
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3077 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
3078 obj.Register(who)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3079 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3080
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3081 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
3082 var myObserver = Observer.new()
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3083
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3084 Observe(p, myObserver)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3085
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3086 p.Set(true)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3087 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3088 v9.CheckSourceSuccess(lines)
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3089 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3090
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3091 " 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
3092 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
3093 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
3094 vim9script
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3095
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3096 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
3097 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
3098
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3099 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
3100 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
3101 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
3102 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3103
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3104 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
3105 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
3106 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3107 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3108
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3109 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
3110 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3111
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3112 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
3113 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
3114 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3115
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3116 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
3117 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
3118
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3119 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
3120 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
3121 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
3122 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3123 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
3124 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3125
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3126 def Test_instanceof()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3127 var lines =<< trim END
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3128 vim9script
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3129
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3130 class Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3131 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3132
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3133 class Base2 extends Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3134 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3135
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3136 interface Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3137 endinterface
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3138
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3139 class Mix1 implements Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3140 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3141
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3142 class Base3 extends Mix1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3143 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3144
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3145 var b1 = Base1.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3146 var b2 = Base2.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3147 var b3 = Base3.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3148
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3149 assert_true(instanceof(b1, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3150 assert_true(instanceof(b2, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3151 assert_false(instanceof(b1, Base2))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3152 assert_true(instanceof(b3, Mix1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3153 assert_false(instanceof(b3, []))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3154 assert_true(instanceof(b3, [Base1, Base2, Intf1]))
33019
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3155
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3156 def Foo()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3157 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
3158 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
3159 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
3160
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3161 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
3162 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
3163 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
3164 assert_true(instanceof(a3, Mix1))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3165 assert_false(instanceof(a3, []))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3166 assert_true(instanceof(a3, [Base1, Base2, Intf1]))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3167 enddef
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3168 Foo()
33291
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3169
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3170 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
3171 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
3172
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3173 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3174 v9.CheckSourceSuccess(lines)
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3175 enddef
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3176
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3177 " 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
3178 " 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
3179 " 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
3180 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
3181 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
3182 vim9script
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3183
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3184 class Widget
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3185 this._lnum: number = 1
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3186
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3187 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
3188 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
3189 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3190
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3191 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
3192 return ''
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3193 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3194 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3195
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3196 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
3197 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
3198 return '<Foo>'
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3199 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3200 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3201
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3202 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
3203 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
3204 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
3205 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
3206 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3207
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3208 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
3209 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
3210 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
3211 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3212 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
3213 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3214
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
3215 " 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
3216 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
3217 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
3218 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
3219
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3220 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
3221 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
3222 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
3223 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
3224 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
3225 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
3226
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3227 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
3228 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
3229 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
3230 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
3231
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3232 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
3233 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
3234 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
3235
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3236 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
3237 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
3238 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
3239 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
3240
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3241 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
3242 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
3243 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
3244 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
3245
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3246 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
3247 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
3248 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
3249 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
3250
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3251 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
3252 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
3253 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
3254 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
3255 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
3256
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3257 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
3258 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
3259 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
3260 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
3261 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
3262
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3263 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
3264 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
3265 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
3266 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
3267 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
3268
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3269 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
3270 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
3271 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
3272 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
3273 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
3274
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3275 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
3276 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
3277 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
3278 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
3279 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
3280 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
3281 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
3282 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
3283 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
3284 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
3285 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3286 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
3287 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
3288
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3289 " 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
3290 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
3291 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
3292 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
3293
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3294 class A
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
3295 public this.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
3296 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
3297
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3298 class B extends A
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
3299 public this.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
3300 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
3301
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3302 class C extends B
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
3303 public this.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
3304 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
3305
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3306 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
3307 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
3308 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
3309
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3310 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
3311 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
3312 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
3313 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
3314
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3315 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
3316 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
3317 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
3318 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
3319 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
3320
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3321 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
3322 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
3323 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
3324 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
3325 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
3326 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
3327 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
3328 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3329 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
3330 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
3331
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3332 " 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
3333 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
3334 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
3335 vim9script
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3336
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3337 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
3338 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
3339 F0()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3340 enddef
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3341 endclass
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3342
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3343 def F0()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3344 assert_match('<SNR>\d\+_F\[1\]\.\.C\.M1\[1\]\.\.<SNR>\d\+_F0\[1\]$', expand('<stack>'))
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3345 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3346
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3347 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
3348 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
3349 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3350
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3351 F()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3352 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3353 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
3354 enddef
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3355
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3356 " 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
3357 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
3358 # 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
3359 var lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3360 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3361
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3362 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3363 this._bufnr: number
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3364
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3365 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3366 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3367 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3368 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3369 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3370 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3371
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3372 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
3373 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
3374
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3375 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3376 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3377 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
3378
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3379 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3380 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3381 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3382 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
3383 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3384 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3385 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3386 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3387
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3388 # 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
3389 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3390 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3391
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3392 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3393 this._bufnr: number
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3394
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3395 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3396 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3397 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3398 return
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3399 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3400 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3401 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3402
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3403 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
3404 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
3405
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3406 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3407 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3408 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
3409
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3410 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3411 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3412 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3413 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
3414 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3415 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3416 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3417 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3418
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3419 # 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
3420 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3421 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3422
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3423 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3424 this._bufnr: number
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3425
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3426 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
3427 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3428 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3429 return this
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3430 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3431 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3432 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3433 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
3434 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
3435
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3436 # 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
3437 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3438 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3439
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3440 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3441 this._state: dict<any>
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3442
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3443 def new(): dict<any>
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3444 this._state = {}
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3445 return this._state
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3446 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3447 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3448
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3449 var c = C.new()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3450 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
3451 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
3452 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
3453 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3454
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3455 " 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
3456 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
3457 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
3458 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3459
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3460 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
3461
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3462 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
3463 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
3464 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
3465 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
3466 else
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3467 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
3468 endif
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3469 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3470
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3471 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
3472 this._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
3473 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3474
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3475 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
3476 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
3477 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
3478 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
3479 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3480
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3481 " 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
3482 " object.
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3483 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
3484 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
3485 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3486
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3487 class C
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3488 this.val: number
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3489 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
3490 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3491 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3492
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3493 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
3494 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
3495
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3496 var current: C
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3497 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
3498 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
3499 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
3500 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
3501
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3502 def F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3503 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
3504 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3505
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3506 def G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3507 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
3508 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3509
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3510 F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3511 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
3512 G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3513 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
3514 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3515 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
3516 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3517
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3518 " 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
3519 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
3520 # 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
3521 # 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
3522 # 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
3523 # Also different depths
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3524
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3525 # TODO: handle inside_class in vim9class
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3526 # lockvar of a read-only currently fails even if inside
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3527
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3528 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3529 # 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
3530 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3531
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3532 # 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
3533 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3534 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3535
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3536 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3537 this.val1: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3538 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3539 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3540 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3541 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3542 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
3543 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3544 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3545 # TODO: wrong error
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3546 v9.CheckSourceFailure(lines, 'E1335: Variable "val1" 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
3547
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3548 # 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
3549 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3550 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3551
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3552 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3553 this.val2: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3554 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3555 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
3556 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3557 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3558 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
3559
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3560 # 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
3561 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3562 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3563
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3564 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3565 this.val3: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3566 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3567 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
3568 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3569 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3570 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3571 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3572 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3573 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
3574
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3575 # 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
3576 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3577 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3578
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3579 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3580 this.val4: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3581 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3582 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3583 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3584 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3585 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3586 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3587 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
3588
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3589 # 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
3590 # 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
3591
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3592 # 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
3593 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3594 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3595
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3596 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3597 this.val5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3598 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
3599 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3600 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3601 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3602 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
3603 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
3604 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3605 # TODO: wrong error, tricky since type "any"
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3606 v9.CheckSourceFailure(lines, 'E1335: Variable "val5" 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
3607
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3608 # 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
3609 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3610 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3611
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3612 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3613 this.val6: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3614 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
3615 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3616 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3617 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3618 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
3619 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3620 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3621 # TODO: wrong error, tricky since type "any"
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3622 v9.CheckSourceFailure(lines, 'E1335: Variable "val6" 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
3623
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3624 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3625 # 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
3626 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3627
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3628 # lockvar from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3629 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3630 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3631
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3632 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3633 public this.val1: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3634 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3635 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3636 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3637 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3638 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
3639 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3640 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3641 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
3642
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3643 # lockvar from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3644 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3645 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3646
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3647 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3648 public this.val2: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3649 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3650 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
3651 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3652 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3653 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
3654
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3655 # 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
3656 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3657 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3658
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3659 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3660 public this.val3: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3661 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3662 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
3663 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3664 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3665 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3666 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3667 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3668 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
3669
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3670 # 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
3671 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3672 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3673
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3674 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3675 public this.val4: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3676 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3677 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3678 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3679 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3680 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3681 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3682 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
3683
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3684 # 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
3685 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3686 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3687
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3688 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3689 public this.val5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3690 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
3691 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3692 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3693 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3694 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
3695 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
3696 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3697 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
3698
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3699 # 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
3700 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3701 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3702
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3703 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3704 public this.val6: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3705 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
3706 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3707 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3708 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3709 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
3710 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3711 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3712 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
3713 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3714
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3715 " 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
3716 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
3717
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3718 # 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
3719 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3720 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3721
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3722 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3723 public static sval1: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3724 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3725 lockvar sval1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3726 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3727 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3728 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3729 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3730 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3731 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
3732
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3733 # 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
3734 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3735 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3736
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3737 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3738 public static sval2: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3739 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3740 lockvar C.sval2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3741 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3742 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3743 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3744 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3745 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3746 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
3747
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3748 # 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
3749 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3750 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3751
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3752 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3753 public static sval3: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3754 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3755 lockvar sval3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3756 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3757 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3758 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3759 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3760 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
3761
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3762 # 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
3763 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3764 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3765
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3766 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3767 public static sval4: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3768 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3769 lockvar C.sval4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3770 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3771 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3772 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3773 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3774 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
3775
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3776 # 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
3777 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3778 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3779
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3780 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3781 public static sval5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3782 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3783 lockvar C.sval5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3784 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3785 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
3786
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3787 # 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
3788 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3789 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3790
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3791 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3792 public static sval6: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3793 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3794 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3795 lockvar o.sval6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3796 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3797 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
3798 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3799
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3800 " 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
3801 def Test_lockvar_argument()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3802 # Lockvar a function arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3803 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3804 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3805
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3806 def Lock(val: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3807 lockvar val
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3808 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3809
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3810 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
3811 Lock(d)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3812
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3813 d->extend({c: 3})
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3814 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3815 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
3816
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3817 # 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
3818 # 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
3819 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3820 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3821
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3822 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3823 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3824 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3825
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3826 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3827 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3828 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3829
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3830 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3831 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3832 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3833 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3834
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3835 # Lock a class.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3836 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3837 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3838
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3839 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3840 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3841 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3842
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3843 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3844 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3845 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3846
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3847 Lock2(C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3848 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3849 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3850
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3851 # Lock an object.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3852 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3853 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3854
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3855 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3856 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3857 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3858
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3859 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3860 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3861 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3862
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3863 Lock2(C.new())
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3864 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3865 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3866
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3867 # 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
3868 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3869 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3870
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3871 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3872 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3873 def Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3874 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3875 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3876 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3877
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3878
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3879 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3880 o.Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3881 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3882 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
3883 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3884
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3885 " 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
3886 def Test_lockvar_this()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3887 # lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3888 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3889 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3890 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3891 def TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3892 lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3893 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3894 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3895 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3896 o.TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3897 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3898 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3899
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3900 # 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
3901 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3902 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3903 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3904 def TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3905 var four: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3906 lockvar four
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3907 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3908 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3909 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3910 o.TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3911 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3912 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
3913
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3914 # 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
3915 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3916 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3917 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3918 def TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3919 var this5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3920 lockvar this5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3921 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3922 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3923 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3924 o.TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3925 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3926 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
3927 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3928
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3929 " 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
3930 def Test_lockvar_general()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3931 # 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
3932 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3933 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3934 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3935 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3936 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3937 lockvar o
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3938 lockvar C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3939 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3940 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3941
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3942 # 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
3943 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3944 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3945
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3946 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3947 public this.val: list<list<number>> = [ [1], [2], [3] ]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3948 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3949 def Lock2(obj: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3950 lockvar obj.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3951 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3952
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3953 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3954 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3955 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3956 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
3957 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3958 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3959 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
3960 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3961 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3962 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3963 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3964 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
3965 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3966 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3967
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3968 # 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
3969 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3970 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3971
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3972 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3973 public this.val: list<list<number>> = [ [1], [2], [3] ]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3974 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3975
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3976 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3977 lockvar o.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3978 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3979 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
3980 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3981 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3982 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
3983 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3984 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3985 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3986 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3987 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
3988 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3989 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3990 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3991
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
3992 " Test for a private object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
3993 def Test_private_object_method()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
3994 # Try calling a private method using an object (at the script level)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
3995 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
3996 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
3997
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
3998 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
3999 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4000 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4001 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4002 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4003 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
4004 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4005 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
4006 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 9)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4007
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4008 # Try calling a private method using an object (from a def function)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4009 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4010 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4011
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4012 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4013 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4014 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4015 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4016 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4017 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4018 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
4019 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4020 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4021 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4022 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
4023 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4024
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4025 # Use a private method from another object method (in script context)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4026 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4027 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4028
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4029 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4030 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4031 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4032 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4033 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4034 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4035 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4036 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4037 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
4038 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
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)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4041
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4042 # Use a private method from another object method (def function context)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4043 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4044 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4045
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4046 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4047 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4048 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4049 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4050 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4051 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4052 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4053 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4054 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4055 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
4056 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
4057 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4058 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4059 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4060 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
4061
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4062 # Try calling a private method without the "this" prefix
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4063 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4064 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4065
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4066 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4067 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4068 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4069 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4070 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4071 return _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4072 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4073 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4074 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
4075 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4076 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
4077 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
4078
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4079 # Try calling a private method using the class name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4080 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4081 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4082
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4083 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4084 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4085 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4086 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4087 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4088 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4089 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
4090 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 8)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4091
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4092 # Define two private methods with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4093 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4094 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4095
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4096 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4097 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4098 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4099 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4100 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4101 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4102 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
4103 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
4104 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
4105
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4106 # Define a private method and a object method with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4107 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4108 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4109
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4110 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4111 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4112 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4113 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4114 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4115 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4116 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
4117 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
4118 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
4119
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4120 # Define an object method and a private method with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4121 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4122 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4123
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4124 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4125 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4126 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4127 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4128 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4129 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4130 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
4131 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
4132 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
4133
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4134 # Call a public method and a private method from a private method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4135 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4136 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4137
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4138 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4139 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4140 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4141 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4142 def _Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4143 return 200
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4144 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4145 def _Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4146 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
4147 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
4148 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4149 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4150 this._Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4151 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4152 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4153 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
4154 a.T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4155 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4156 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
4157
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4158 # Try calling a private method from another class
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4159 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4160 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4161
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4162 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4163 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4164 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4165 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4166 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4167 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4168 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4169 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
4170 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4171 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4172 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4173 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
4174 b.Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4175 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
4176 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4177
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4178 # Call a private object method from a child class object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4179 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4180 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4181 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4182 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4183 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4184 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4185 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4186 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
4187 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4188 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4189 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4190 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
4191 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4192 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4193 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4194 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4195 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
4196 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
4197 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4198 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
4199
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4200 # Call a private object method from a child class object
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4201 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4202 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4203 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4204 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4205 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4206 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4207 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4208 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
4209 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4210 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4211 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4212 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
4213 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4214 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4215 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4216 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
4217 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
4218 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
4219 v9.CheckSourceFailure(lines, 'E1366: Cannot access private 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
4220
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4221 # 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
4222 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4223 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4224 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4225 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4226 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4227 var a = _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4228 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
4229 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
4230 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4231
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4232 " Test for an private class method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4233 def Test_private_class_method()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4234 # Try calling a class private method (at the script level)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4235 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
4236 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4237
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4238 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4239 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
4240 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4241 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4242 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4243 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4244 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
4245 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 8)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4246
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4247 # Try calling a class private method (from a def function)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4248 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4249 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4250
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4251 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4252 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
4253 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4254 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4255 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4256 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4257 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4258 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4259 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4260 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
4261 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4262
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4263 # Try calling a class private method using an object (at the script level)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4264 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4265 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4266
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4267 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4268 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
4269 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4270 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4271 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4272 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
4273 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4274 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
4275 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 9)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4276
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4277 # Try calling a class private method using an object (from a def function)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4278 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4279 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4280
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4281 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4282 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
4283 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4284 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4285 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4286 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4287 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
4288 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4289 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4290 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4291 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
4292 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4293
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4294 # Use a class private method from an object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4295 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4296 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4297
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4298 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4299 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
4300 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4301 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4302 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
4303 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
4304 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4305 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4306 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
4307 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4308 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4309 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
4310
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
4311 # Use a class private method from another class private method without the
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
4312 # 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
4313 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4314 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4315
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4316 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4317 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
4318 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4319 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4320 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
4321 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
4322 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4323 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
4324 _Foo2()
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4325 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4326 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4327 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
4328 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4329 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4330 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
4331
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4332 # Declare a class method and a class private method with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4333 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4334 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4335
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4336 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4337 static def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4338 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4339 static def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4340 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4341 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4342 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
4343 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
4344 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
4345
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4346 # Try calling a class private method from another class
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4347 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4348 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4349
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4350 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4351 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
4352 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4353 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4354 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4355 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4356 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4357 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4358 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4359 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4360 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
4361 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
4362 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
4363 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4364
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4365 # Call a private class method from a child class object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4366 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4367 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4368 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4369 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
4370 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4371 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4372 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4373 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
4374 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4375 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4376 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4377 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
4378 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4379 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4380 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4381 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4382 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
4383 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
4384 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
4385 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4386
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4387 # Call a private class method from a child class private class method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4388 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4389 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4390 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4391 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
4392 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4393 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4394 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4395 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
4396 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4397 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4398 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4399 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
4400 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
4401 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4402 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4403 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4404 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
4405 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
4406 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4407
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4408 # Call a private class method from a child class object
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4409 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4410 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4411 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4412 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
4413 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4414 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4415 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4416 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
4417 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4418 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4419 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4420 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
4421 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4422 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4423 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4424 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
4425 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
4426 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
4427 v9.CheckSourceFailure(lines, 'E1325: Method not found on class "C": _Foo', 16)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4428 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4429
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4430 " 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
4431 " argument.
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4432 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
4433 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
4434 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4435
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4436 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
4437 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
4438 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
4439 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4440 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4441
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4442 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
4443 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
4444 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4445
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4446 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
4447 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
4448 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4449
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4450 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
4451 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
4452 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4453 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
4454
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4455 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
4456 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4457
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4458 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
4459 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
4460 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
4461 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4462 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4463
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4464 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
4465 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
4466 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4467
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4468 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
4469 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
4470 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4471
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4472 Baz()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4473 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4474 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
4475 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4476
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4477 def Test_static_inheritence()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4478 # 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
4479 var lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4480 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4481
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4482 class 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
4483 static _svar: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4484 this._mvar: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4485 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
4486 _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
4487 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
4488 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4489 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
4490 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
4491 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4492 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
4493 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
4494 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4495 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4496
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4497 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
4498 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
4499 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
4500 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4501 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4502
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4503 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
4504 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
4505 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
4506 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4507
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4508 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
4509 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
4510 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
4511 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4512 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4513
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4514 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4515 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4516 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4517 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
4518 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
4519 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
4520
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33337
diff changeset
4521 assert_fails('echo oc.AccessPrivateStaticThroughClassName()', 'E1333: Cannot access private variable: _svar')
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4522
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4523 # 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
4524 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
4525 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
4526 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
4527 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4528 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4529 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4530
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4531 " 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
4532 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
4533 # 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
4534 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
4535 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4536 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4537 this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4538 this.val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4539 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4540 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
4541 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
4542
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4543 # Duplicate private member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4544 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
4545 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4546 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4547 this._val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4548 this._val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4549 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4550 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
4551 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
4552
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4553 # 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
4554 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
4555 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4556 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4557 public this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4558 public this.val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4559 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4560 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
4561 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
4562
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4563 # Duplicate private member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4564 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
4565 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4566 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4567 this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4568 this._val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4569 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4570 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
4571 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
4572
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4573 # Duplicate public and private member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4574 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
4575 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4576 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4577 this._val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4578 public this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4579 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4580 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
4581 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
4582
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4583 # 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
4584 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
4585 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4586 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4587 static s: string = "abc"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4588 static _s: string = "def"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4589 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4590 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
4591 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
4592
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4593 # Duplicate public and private 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
4594 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
4595 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4596 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4597 public static s: string = "abc"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4598 static _s: string = "def"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4599 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4600 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
4601 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
4602
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4603 # 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
4604 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
4605 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4606 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4607 static val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4608 this.val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4609 def new()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4610 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4611 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4612 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
4613 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
4614 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
4615 END
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
4616 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
4617
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4618 # 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
4619 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
4620 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4621 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4622 this.val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4623 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4624 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
4625 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4626 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4627 this.val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4628 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4629 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
4630 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
4631
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4632 # Duplicate object private 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
4633 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
4634 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4635 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4636 this._val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4637 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4638 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
4639 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4640 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4641 this._val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4642 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4643 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
4644 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
4645
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4646 # Duplicate object private 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
4647 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
4648 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4649 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4650 this.val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4651 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4652 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
4653 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4654 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4655 this._val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4656 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4657 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
4658 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
4659
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4660 # 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
4661 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
4662 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4663 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4664 this._val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4665 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4666 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
4667 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4668 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4669 this.val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4670 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
4671 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
4672 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
4673
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4674 # 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
4675 lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4676 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4677 class A
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4678 public static svar2: number
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4679 public static svar: number
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4680 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4681 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4682 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
4683 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
4684
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4685 " Test for accessing a private member outside a class in a def function
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4686 def Test_private_member_access_outside_class()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4687 # private object member variable
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4688 var lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4689 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4690 class A
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4691 this._val = 10
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4692 def GetVal(): number
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4693 return this._val
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4694 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4695 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4696 def T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4697 var a = A.new()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4698 a._val = 20
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4699 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4700 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4701 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
4702 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable: _val', 2)
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4703
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4704 # access a non-existing private object member variable
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4705 lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4706 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4707 class A
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4708 this._val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4709 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4710 def T()
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4711 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
4712 a._a = 1
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4713 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4714 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4715 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
4716 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "A": _a', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4717
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4718 # private static member variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4719 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4720 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4721 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4722 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4723 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4724 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4725 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4726 var x = a._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4727 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4728 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4729 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
4730 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
4731
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4732 # private static member variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4733 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4734 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4735 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4736 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4737 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4738 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4739 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4740 a._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4741 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4742 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4743 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
4744 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
4745
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4746 # private static class variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4747 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4748 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4749 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4750 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4751 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4752 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4753 var x = A._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4754 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4755 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4756 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
4757 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable: _val', 1)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4758
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4759 # private static class variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4760 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4761 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4762 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4763 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4764 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4765 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4766 A._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4767 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4768 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
4769 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
4770 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable: _val', 1)
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4771 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4772
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4773 " 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
4774 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
4775 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
4776 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4777 interface A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
4778 this.val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4779 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4780 class B implements A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
4781 public this.val = 10
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4782 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4783 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
4784 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
4785
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4786 lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4787 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4788 interface A
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4789 this.val: number
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4790 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4791 class B implements A
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4792 public this.val = 10
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4793 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4794 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
4795 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
4796 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4797
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4798 " 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
4799 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
4800 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
4801 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4802 class A
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4803 this.val: number
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4804 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4805 def T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4806 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
4807 a.val = 20
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4808 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4809 T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
4810 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
4811 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
4812 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
4813
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4814 " 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
4815 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
4816 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
4817 vim9script
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4818 class A
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4819 this.var1: number = 10
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
4820 public static var2: list<number> = [1, 2]
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
4821 public static var3: dict<number> = {a: 1, b: 2}
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4822 static _priv_var4: number = 40
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4823 endclass
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4824 def T()
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
4825 assert_equal([1, 2], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
4826 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
4827 A.var2 = [3, 4]
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
4828 A.var3 = {c: 3, d: 4}
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
4829 assert_equal([3, 4], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
4830 assert_equal({c: 3, d: 4}, A.var3)
33343
41b50abddeea patch 9.0.1935: Vim9: not consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33337
diff changeset
4831 assert_fails('echo A._priv_var4', 'E1333: Cannot access private variable: _priv_var4')
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4832 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4833 T()
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4834 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4835 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
4836 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
4837
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4838 " 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
4839 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
4840 var lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4841 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4842 class A
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4843 public static svar1: list<number> = [1]
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4844 public static svar2: list<number> = [2]
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4845 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4846
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4847 A.svar1->add(3)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4848 A.svar2->add(4)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4849 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
4850 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
4851
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4852 def Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4853 A.svar1->add(7)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4854 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
4855 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
4856 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
4857 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4858 Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4859 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4860 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
4861
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4862 # 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
4863 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4864 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4865 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4866 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4867 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4868 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4869
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4870 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
4871 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4872 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
4873 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
4874
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4875 # 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
4876 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4877 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4878 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4879 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4880 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4881 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4882
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4883 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
4884 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4885 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
4886 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
4887
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4888 # 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
4889 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4890 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4891 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4892 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4893 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4894 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4895
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4896 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4897 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
4898 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4899 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4900 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4901 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
4902 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
4903
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4904 # 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
4905 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4906 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4907 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4908 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4909 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4910 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4911
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4912 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4913 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
4914 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4915 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4916 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
4917 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
4918 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
4919 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
4920
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
4921 " 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
4922 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
4923 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
4924 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
4925
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4926 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
4927 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
4928 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
4929
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4930 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
4931 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
4932 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
4933 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
4934 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
4935
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4936 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
4937 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
4938 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
4939 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
4940 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
4941
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4942 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
4943 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
4944 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
4945
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4946 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
4947 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
4948 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
4949
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4950 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
4951 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
4952 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
4953 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4954 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
4955 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
4956
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4957 " 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
4958 " 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
4959 " 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
4960 " 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
4961 " 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
4962 " 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
4963 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4964 " 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
4965 " 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
4966 " 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
4967 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4968 " 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
4969 " 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
4970 " 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
4971 " 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
4972 " 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
4973 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4974 " 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
4975 " 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
4976 " 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
4977 " 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
4978 " 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
4979 " 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
4980 " 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
4981 " 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
4982 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4983 " 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
4984 " 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
4985 " 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
4986 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4987 " 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
4988 " 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
4989 " 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
4990 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
4991 " 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
4992 " 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
4993 " 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
4994 " END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4995 " 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
4996 " 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
4997
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
4998 " Test for abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
4999 def Test_abstract_method()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5000 # Use two abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5001 var lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5002 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5003 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5004 def M1(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5005 return 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5006 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5007 abstract def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5008 abstract def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5009 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5010 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5011 def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5012 return 20
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5013 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5014 def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5015 return 30
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5016 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5017 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5018 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5019 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
5020 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5021 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5022
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5023 # 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
5024 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5025 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5026 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5027 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5028 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5029 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5030 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5031 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
5032 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
5033
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5034 # 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
5035 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5036 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5037 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5038 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5039 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5040 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5041 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5042 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
5043 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
5044
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5045 # 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
5046 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5047 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5048 interface A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5049 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5050 endinterface
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5051 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
5052 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
5053 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5054 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5055 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5056 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5057
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5058 # Abbreviate the "abstract" keyword
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5059 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5060 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5061 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5062 abs def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5063 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5064 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
5065 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
5066
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5067 # 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
5068 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5069 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5070 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5071 abstract this.val = 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5072 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5073 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
5074 v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def" or "static"', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5075
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5076 # Use a static abstract method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5077 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5078 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5079 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5080 abstract static def Foo(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5081 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5082 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5083 static def Foo(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5084 return 4
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5085 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5086 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5087 assert_equal(4, B.Foo())
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5088 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5089 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5090
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5091 # 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
5092 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5093 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5094 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5095 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
5096 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5097 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5098 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
5099 return []
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5100 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5101 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5102 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
5103 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
5104
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5105 # Use an abstract class to invoke an abstract method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5106 # FIXME: This should fail
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5107 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5108 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5109 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5110 abstract static def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5111 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5112 A.Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5113 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5114 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5115
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5116 # 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
5117 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5118 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5119 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5120 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
5121 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5122 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5123 def Foo(): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5124 return [3, 5]
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5125 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5126 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5127 def Bar(c: B)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5128 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
5129 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5130 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5131 Bar(b)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5132 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5133 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5134 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5135
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5136 " 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
5137 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
5138 # 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
5139 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5140 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5141
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5142 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5143 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5144 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5145 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5146 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5147
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5148 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5149 def Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5150 Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5151 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5152 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5153
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5154 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5155 b.Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5156 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
5157 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
5158 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5159
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5160 " 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
5161 " script context.
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5162 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
5163 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5164 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
5165 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5166 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5167 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
5168 return ['a', 'b']
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5169 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5170 def Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5171 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
5172 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
5173 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5174 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5175
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5176 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5177 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
5178 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
5179 t_a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5180 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5181
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5182 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
5183 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
5184 a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5185 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5186 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5187 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
5188
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5189 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5190 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5191 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5192 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5193 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
5194 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5195 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5196 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5197
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5198 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
5199 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
5200 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
5201 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
5202
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5203 # def function context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5204 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5205 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5206 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5207 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
5208 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5209 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5210 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5211
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5212 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5213 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
5214 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
5215 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5216 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5217 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
5218 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
5219 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5220
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5221 def Test_class_variable()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5222 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5223 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5224
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5225 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5226 public static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5227 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5228 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5229 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5230 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5231 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5232 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5233 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5234
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5235 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5236 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5237
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5238 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
5239 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5240 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5241 a.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5242 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5243 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5244
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5245 def T1(a1: A)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5246 a1.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5247 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5248 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5249 T1(b)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5250
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5251 A.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5252 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
5253 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5254 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5255
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5256 # 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
5257 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5258 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5259
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5260 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5261 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5262 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5263
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5264 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5265 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5266 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5267 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5268 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5269 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5270 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
5271 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
5272
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5273 # 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
5274 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5275 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5276
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5277 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5278 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5279 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5280
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5281 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5282 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5283 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5284 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5285 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5286 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5287 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
5288 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
5289
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5290 # 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
5291 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5292 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5293
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5294 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5295 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5296 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5297
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5298 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5299 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5300 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5301 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5302 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5303 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5304 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5305 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
5306 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
5307
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5308 # 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
5309 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5310 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5311
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5312 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5313 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5314 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5315
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5316 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5317 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5318 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5319 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5320 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5321 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5322 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5323 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
5324 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
5325
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5326 # 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
5327 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5328 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5329
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5330 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5331 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5332 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5333 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5334 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5335 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
5336 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
5337
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5338 # 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
5339 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5340 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5341
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5342 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5343 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5344 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5345 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5346 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5347 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
5348 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
5349
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5350 # 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
5351 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5352 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5353
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5354 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5355 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5356 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5357
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5358 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5359 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5360 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5361 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5362 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5363 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
5364 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
5365
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5366 # 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
5367 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5368 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5369
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5370 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5371 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5372 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5373 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5374 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5375 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5376 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5377 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5378 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
5379 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
5380 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5381
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5382 " 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
5383 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
5384 # 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
5385 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5386 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5387 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5388 static sval = 100
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5389 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5390 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5391 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5392 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5393 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5394 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5395 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5396
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5397 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5398 static sval = 200
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5399 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5400 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5401 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5402 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5403 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5404 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5405 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5406
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5407 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
5408 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5409 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5410
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5411 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
5412 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5413 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5414
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5415 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
5416 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
5417 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5418 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
5419 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5420 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
5421 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
5422 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
5423 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5424 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5425
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5426 # 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
5427 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5428 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5429 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5430 static sval = 100
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5431 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5432 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5433 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5434 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5435 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5436 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5437 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5438
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5439 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5440 static sval = 200
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5441 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5442 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5443 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5444 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5445
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5446 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
5447 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5448 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5449
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5450 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
5451 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5452 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5453
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5454 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
5455 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
5456 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5457 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
5458 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5459 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
5460 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
5461 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
5462 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5463 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5464 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5465
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5466 " 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
5467 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
5468 # 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
5469 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5470 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5471 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5472 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5473 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5474 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5475 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5476 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5477 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
5478 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
5479
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5480 # 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
5481 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5482 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5483 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5484 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5485 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5486 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5487 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5488 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5489 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5490 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5491 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5492 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
5493 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
5494 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5495
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5496 " 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
5497 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
5498 # Duplicate instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5499 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5500 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5501 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5502 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5503 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5504 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5505 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5506 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5507 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
5508 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
5509
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5510 # Duplicate private instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5511 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5512 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5513 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5514 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5515 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5516 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5517 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5518 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5519 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
5520 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
5521
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5522 # Duplicate class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5523 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5524 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5525 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5526 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5527 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5528 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5529 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5530 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5531 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
5532 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
5533
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5534 # Duplicate private class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5535 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5536 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5537 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5538 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5539 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5540 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5541 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5542 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5543 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
5544 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
5545
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5546 # Duplicate private class and object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5547 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5548 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5549 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5550 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5551 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5552 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5553 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5554 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5555 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
5556 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
5557 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5558
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5559 " 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
5560 " methods.
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5561 def Test_instance_method_access_level()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5562 # Private method in subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5563 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5564 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5565 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5566 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5567 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5568 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5569 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5570 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5571 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5572 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5573 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5574 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5575 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
5576 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
5577
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5578 # Public method in subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5579 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5580 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5581 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5582 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5583 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5584 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5585 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5586 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5587 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5588 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5589 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5590 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5591 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
5592 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
5593 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5594
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5595 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
5596 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5597 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5598 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5599 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5600 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5601 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5602 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5603 public static rw_class_var = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5604 public this.rw_obj_var = 2
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5605 static def ClassMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5606 return 3
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5607 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5608 def ObjMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5609 return 4
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5610 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5611 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5612 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
5613 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
5614 var c = C.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5615 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
5616 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
5617 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5618 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
5619 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5620
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5621 " A interface cannot have a static variable or a static method or a private
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5622 " variable or a private 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
5623 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
5624 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
5625 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5626 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
5627 static num: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5628 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5629 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
5630 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
5631
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5632 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
5633 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5634 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
5635 static _num: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5636 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5637 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
5638 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
5639
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5640 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
5641 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5642 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
5643 public static num: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5644 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5645 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
5646 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
5647
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5648 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
5649 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5650 interface A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5651 public static num: number
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5652 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5653 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
5654 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
5655
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5656 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
5657 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5658 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5659 static _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
5660 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5661 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
5662 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
5663
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5664 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
5665 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5666 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
5667 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
5668 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5669 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
5670 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
5671
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5672 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
5673 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5674 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
5675 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
5676 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5677 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
5678 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
5679
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5680 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
5681 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5682 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
5683 this._Foo: 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
5684 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5685 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
5686 v9.CheckSourceFailure(lines, 'E1379: Private 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
5687
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5688 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
5689 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5690 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
5691 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
5692 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5693 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
5694 v9.CheckSourceFailure(lines, 'E1380: Private 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
5695 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5696
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5697 " 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
5698 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
5699 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
5700 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5701 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
5702 this.var1: 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
5703 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
5704 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5705 interface B extends A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5706 this.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
5707 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
5708 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5709 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
5710 this.var1 = [1, 2]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5711 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
5712 enddef
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5713 this.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
5714 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
5715 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5716 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5717 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5718 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
5719
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5720 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
5721 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5722 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
5723 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
5724 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5725 interface B extends A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5726 this.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
5727 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5728 class C implements A, B
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5729 this.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
5730 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5731 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
5732 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
5733
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5734 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
5735 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5736 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
5737 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
5738 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5739 interface B extends A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5740 this.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
5741 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5742 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
5743 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
5744 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5745 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5746 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
5747 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
5748
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5749 # 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
5750 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
5751 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5752 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
5753 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5754 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
5755 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5756 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
5757 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
5758
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5759 # 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
5760 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
5761 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5762 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
5763 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5764 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
5765 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5766 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
5767 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
5768
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5769 # 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
5770 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
5771 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5772 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
5773 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5774 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
5775 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5776 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
5777 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
5778
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5779 # 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
5780 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
5781 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5782 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
5783 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5784 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
5785 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5786 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
5787 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5788 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
5789 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
5790
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5791 # 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
5792 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
5793 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5794 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
5795 this.val1: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5796 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5797 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
5798 this.val2: string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5799 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5800 interface C extends B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5801 this.val1: string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5802 this.val2: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5803 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5804 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
5805 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
5806 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5807
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5808 " 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
5809 " 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
5810 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
5811 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
5812 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5813
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5814 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
5815 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
5816 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
5817 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
5818 this.var1: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5819 this.var2: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5820 this.var3: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5821 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5822
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5823 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
5824 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
5825 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5826 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
5827 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
5828 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5829 this.v1: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5830 this.var3 = [{c: 30}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5831 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5832
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5833 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
5834 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
5835 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5836 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
5837 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
5838 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5839 this.v2: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5840 this.var2 = [{b: 20}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5841 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5842
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5843 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
5844 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
5845 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5846 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
5847 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
5848 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5849 this.v3: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5850 this.var1 = [{a: 10}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5851 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5852
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5853 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
5854 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
5855 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
5856 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
5857 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
5858 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
5859 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
5860 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5861
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5862 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
5863 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
5864 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
5865 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
5866 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
5867 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
5868 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
5869 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
5870 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5871 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
5872
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5873 # 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
5874 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
5875 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5876
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5877 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
5878 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
5879 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
5880 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
5881 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5882
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5883 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
5884 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
5885 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5886 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5887
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5888 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
5889 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
5890 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5891 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
5892 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5893 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5894
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5895 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
5896 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
5897 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5898 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
5899 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5900 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5901 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
5902 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
5903
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5904 # 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
5905 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
5906 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5907
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5908 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
5909 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
5910 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
5911 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
5912 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5913
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5914 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
5915 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
5916 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
5917 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5918 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
5919 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5920 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5921
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5922 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
5923 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
5924 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5925 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
5926 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5927 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5928
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5929 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
5930 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
5931 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5932 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
5933 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5934 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5935 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
5936 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
5937
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5938 # 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
5939 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
5940 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5941
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5942 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
5943 this.var1: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5944 this.var2: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5945 this.var3: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5946 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5947
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5948 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
5949 this.v1: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5950 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5951
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5952 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
5953 this.v2: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5954 this.var2 = [{b: 20}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5955 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5956
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5957 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
5958 this.v3: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5959 this.var1 = [{a: 10}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5960 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5961 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
5962 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
5963
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5964 # 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
5965 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
5966 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5967
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5968 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
5969 this.var1: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5970 this.var2: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5971 this.var3: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5972 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5973
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5974 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
5975 this.v1: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5976 this.var3: list<dict<string>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5977 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5978
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5979 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
5980 this.v2: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5981 this.var2 = [{b: 20}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5982 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5983
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5984 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
5985 this.v3: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5986 this.var1 = [{a: 10}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5987 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
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, '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
5990 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5991
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5992 " 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
5993 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
5994 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
5995 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5996 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
5997 this.n1: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5998 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
5999 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6000 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
6001 this.n2: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6002 this.n1: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6003 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
6004 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
6005 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6006 class C implements B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6007 this.n1 = 10
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6008 this.n2 = 20
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6009 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
6010 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
6011 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6012 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
6013 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
6014 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6015 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6016 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
6017 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
6018 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
6019 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6020 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
6021 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
6022 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
6023 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
6024 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
6025 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6026 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
6027 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
6028 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
6029 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6030 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
6031 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6032
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6033 " 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
6034 " 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
6035 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
6036 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
6037 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6038 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
6039 this.val: list<dict<string>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6040 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6041 class 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
6042 this.val = [{a: '1'}, {b: '2'}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6043 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6044 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
6045 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
6046 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6047 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
6048
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6049 # 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
6050 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
6051 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6052 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
6053 this.val: list<dict<string>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6054 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6055 class 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
6056 this.val = {a: 1, b: 2}
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6057 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6058 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
6059 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
6060 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
6061 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6062
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6063 " 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
6064 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
6065 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
6066 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6067
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6068 class 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
6069 this.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
6070 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6071
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6072 class 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
6073 this.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
6074 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6075
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6076 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
6077 this.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
6078 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6079
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6080 class 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
6081 this.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
6082 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6083
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6084 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
6085 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
6086 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6087
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6088 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
6089 T(d)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6090 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
6091 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
6092 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6093
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6094 " 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
6095 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
6096 # 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
6097 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
6098 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6099
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6100 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6101 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6102 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
6103 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6104 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6105
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6106 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6107 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6108 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6109 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
6110
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6111 # 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
6112 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6113 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6114
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6115 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6116 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6117 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
6118 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6119 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6120
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6121 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6122 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6123 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6124 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6125 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6126 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6127 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
6128
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6129 # 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
6130 # script context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6131 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6132 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6133
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6134 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6135 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6136 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
6137 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6138
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6139 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
6140 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
6141 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6142 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6143 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6144
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6145 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6146 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6147 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6148 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
6149
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6150 # 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
6151 # def function context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6152 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6153 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6154
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6155 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6156 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6157 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
6158 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6159
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6160 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
6161 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
6162 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6163 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6164 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6165
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6166 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6167 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6168 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6169 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6170 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6171 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6172 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
6173 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6174
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6175 " 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
6176 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
6177 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
6178 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6179
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6180 class Context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6181 public this.state: dict<number> = {}
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6182 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
6183 return this.state
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6184 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6185 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6186
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6187 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
6188 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
6189 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
6190 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
6191
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6192 def F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6193 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
6194 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
6195 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6196 F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6197 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
6198 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
6199 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
6200 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6201 v9.CheckSourceSuccess(lines)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6202 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6203
33337
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6204 " 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
6205 " 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
6206 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
6207 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
6208 vim9script
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6209
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6210 class Context
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6211 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6212
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6213 class Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6214 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6215
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6216 def Failure(): Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6217 return Result.new()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6218 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6219
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6220 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
6221 return Failure()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6222 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6223
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6224 def Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6225 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
6226 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
6227 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6228
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6229 Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6230 END
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6231 v9.CheckSourceSuccess(lines)
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6232 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6233
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6234 " 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
6235 def Test_duplicate_variable()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6236 # 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
6237 var lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6238 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6239 class A
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6240 public static sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6241 public this.sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6242 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6243 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6244 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6245 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
6246
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6247 # 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
6248 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6249 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6250 class A
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6251 public static sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6252 public this.sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6253 def F1()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6254 echo this.sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6255 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6256 static def F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6257 echo sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6258 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6259 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6260 A.F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6261 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6262 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
6263
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6264 # 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
6265 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6266 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6267 class A
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6268 public static sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6269 public this.sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6270 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6271 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6272 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6273 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6274 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6275 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
6276 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6277
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6278 " 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
6279 def Test_reserved_varname()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6280 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
6281 '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
6282 '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
6283
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6284 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
6285 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6286 class C
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6287 public this.{kword}: list<number> = [1, 2, 3]
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6288 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6289 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6290 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6291 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
6292
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6293 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6294 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6295 class C
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6296 public this.{kword}: list<number> = [1, 2, 3]
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6297 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6298 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6299 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6300 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6301 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6302 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
6303
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6304 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6305 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6306 class C
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6307 public this.{kword}: list<number> = [1, 2, 3]
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6308 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6309 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6310 def F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6311 echo this.{kword}
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6312 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6313 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6314 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6315 o.F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6316 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6317 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
6318 endfor
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6319 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6320
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
6321 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker