Mercurial > vim
annotate src/testdir/test_vim9_typealias.vim @ 33944:4cacac1abdb8
runtime(termdebug): add Tbreak command
Commit: https://github.com/vim/vim/commit/323dda1484d95ee5c8a1b2205f8c495446df75ee
Author: iam28th <artyom28th@gmail.com>
Date: Thu Dec 14 20:30:26 2023 +0100
runtime(termdebug): add Tbreak command
closes: https://github.com/vim/vim/issues/13656
Signed-off-by: iam28th <artyom28th@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 14 Dec 2023 20:45:03 +0100 |
parents | 3bba09502b8d |
children | 84b93d95a952 |
rev | line source |
---|---|
33687
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Test Vim9 type aliases |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 source check.vim |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 import './vim9.vim' as v9 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 " Test for :type command to create type aliases |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 def Test_typealias() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 # Use type alias at script level |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 var lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 type ListOfStrings = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 def Foo(a: ListOfStrings): ListOfStrings |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 return a |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 var b: ListOfStrings = ['a', 'b'] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 assert_equal(['a', 'b'], b) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 assert_equal(['e', 'f'], Foo(['e', 'f'])) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 assert_equal('typealias<list<string>>', typename(ListOfStrings)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 assert_equal(v:t_typealias, type(ListOfStrings)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 assert_equal('ListOfStrings', string(ListOfStrings)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 assert_equal(false, null == ListOfStrings) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 v9.CheckSourceSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 # Use type alias at def function level |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 type ListOfStrings = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 def Foo(a: ListOfStrings): ListOfStrings |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 return a |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 def Bar() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 var c: ListOfStrings = ['c', 'd'] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 assert_equal(['c', 'd'], c) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 assert_equal(['e', 'f'], Foo(['e', 'f'])) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 assert_equal('typealias<list<string>>', typename(ListOfStrings)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 assert_equal(v:t_typealias, type(ListOfStrings)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 assert_equal('ListOfStrings', string(ListOfStrings)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 assert_equal(false, null == ListOfStrings) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 Bar() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 v9.CheckSourceSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 # Use :type outside a Vim9 script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 type Index = number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
48 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 v9.CheckSourceFailure(lines, 'E1393: Type can only be defined in Vim9 script', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 # Use :type without any arguments |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 type |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 v9.CheckSourceFailure(lines, 'E1397: Missing type alias name', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 # Use :type with a name but no type |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
59 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
60 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 type MyType |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 v9.CheckSourceFailure(lines, "E398: Missing '=': ", 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
64 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
65 # Use :type with a name but no type following "=" |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
66 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
67 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
68 type MyType = |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
69 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
70 v9.CheckSourceFailure(lines, 'E1398: Missing type alias type', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
71 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
72 # No space before or after "=" |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
75 type MyType=number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
77 v9.CheckSourceFailure(lines, 'E1315: White space required after name: MyType=number', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 # No space after "=" |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
81 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 type MyType =number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
83 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 v9.CheckSourceFailure(lines, "E1069: White space required after '=': =number", 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
85 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
86 # type alias without "=" |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
87 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
88 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
89 type Index number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
90 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
91 v9.CheckSourceFailure(lines, "E398: Missing '=': number", 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
92 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
93 # type alias for a non-existing type |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
94 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
95 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
96 type Index = integer |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
97 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
98 v9.CheckSourceFailure(lines, 'E1010: Type not recognized: integer', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
99 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
100 # type alias starting with lower-case letter |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
101 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
102 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
103 type index = number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
104 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
105 v9.CheckSourceFailure(lines, 'E1394: Type name must start with an uppercase letter: index = number', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
106 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
107 # No white space following the alias name |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
108 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
109 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
110 type Index:number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
111 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
112 v9.CheckSourceFailure(lines, 'E1315: White space required after name: Index:number', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
113 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
114 # something following the type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
115 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
116 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
117 type ListOfNums = list<number> string |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
118 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
119 v9.CheckSourceFailure(lines, 'E488: Trailing characters: string', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
120 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
121 # type alias name collides with a variable name |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
122 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
123 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
124 var ListOfNums: number = 10 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
125 type ListOfNums = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
126 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
127 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "ListOfNums"', 3) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
128 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
129 # duplicate type alias name |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
130 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
131 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
132 type MyList = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
133 type MyList = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
134 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
135 v9.CheckSourceFailure(lines, 'E1396: Type alias "MyList" already exists', 3) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
136 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
137 # def function argument name collision with a type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
138 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
139 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
140 type A = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
141 def Foo(A: number) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
142 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
143 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
144 v9.CheckSourceFailure(lines, 'E1168: Argument already declared in the script: A: number)', 3) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
145 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
146 # def function local variable name collision with a type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
147 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
148 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
149 type A = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
150 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
151 var A: number = 10 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
152 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
153 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
154 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
155 v9.CheckSourceFailure(lines, 'E1054: Variable already declared in the script: A', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
156 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
157 # type alias a variable |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
158 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
159 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
160 var A: list<number> = [] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
161 type B = A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
162 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
163 v9.CheckSourceFailure(lines, 'E1010: Type not recognized: A', 3) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
164 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
165 # type alias a class |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
167 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
168 class C |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
169 endclass |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
170 type AC = C |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
171 assert_equal('class<C>', typename(AC)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
172 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
173 v9.CheckSourceSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
174 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
175 # Sourcing a script twice (which will free script local variables) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
176 # Uses "lines" from the previous test |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
177 new |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
178 setline(1, lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
179 :source |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
180 :source |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
181 bw! |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
182 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
183 # type alias a type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
184 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
185 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
186 type A = string |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
187 type B = A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
188 var b: B = 'abc' |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
189 assert_equal('abc', b) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
190 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
191 var c: B = 'def' |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
192 assert_equal('def', c) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
193 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
194 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
195 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
196 v9.CheckSourceSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
197 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
198 # Assigning to a type alias (script level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
199 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
200 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
201 type MyType = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
202 MyType = [1, 2, 3] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
203 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
204 v9.CheckSourceFailure(lines, 'E1395: Type alias "MyType" cannot be modified', 3) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
205 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
206 # Assigning a type alias (def function level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
208 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
209 type A = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
210 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
211 var x = A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
212 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
213 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
214 END |
33924
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
215 v9.CheckSourceFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
33687
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
216 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
217 # Using type alias in an expression (script level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
218 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
219 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
220 type MyType = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
221 assert_fails('var m = MyType', 'E1403: Type alias "MyType" cannot be used as a value') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
222 assert_fails('var i = MyType + 1', 'E1400: Using type alias "MyType" as a Number') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
223 assert_fails('var f = 1.0 + MyType', 'E1400: Using type alias "MyType" as a Number') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
224 assert_fails('MyType += 10', 'E1395: Type alias "MyType" cannot be modified') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
225 assert_fails('var x = $"-{MyType}-"', 'E1402: Using type alias "MyType" as a String') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
226 assert_fails('var x = MyType[1]', 'E909: Cannot index a special variable') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
227 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
228 v9.CheckSourceSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
229 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
230 # Using type alias in an expression (def function level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
231 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
232 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
233 type MyType = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
234 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
235 var x = MyType + 1 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
238 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
239 v9.CheckSourceFailure(lines, 'E1051: Wrong argument type for +', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
240 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
241 # Using type alias in an expression (def function level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
242 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
243 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
244 type MyType = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
245 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
246 MyType = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
247 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
248 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
249 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
250 v9.CheckSourceFailure(lines, 'E46: Cannot change read-only variable "MyType"', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
251 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
252 # Using type alias in an expression (def function level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
253 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
254 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
255 type MyType = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
256 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
257 MyType += 10 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
258 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
259 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
260 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
261 v9.CheckSourceFailure(lines, 'E46: Cannot change read-only variable "MyType"', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
262 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
263 # Convert type alias to a string (def function level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
264 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
265 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
266 type MyType = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
267 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
268 var x = $"-{MyType}-" |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
269 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
270 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
271 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
272 v9.CheckSourceFailure(lines, 'E1105: Cannot convert typealias to string', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
273 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
274 # Using type alias as a float |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
275 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
276 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
277 type B = number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
278 sort([1.1, B], 'f') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
279 END |
33933
aceaf677dd92
patch 9.0.2163: Vim9: type can be assigned to list/dict
Christian Brabandt <cb@256bit.org>
parents:
33924
diff
changeset
|
280 v9.CheckSourceFailure(lines, 'E1403: Type alias "B" cannot be used as a value', 3) |
33687
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
281 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
282 # Creating a typealias in a def function |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
283 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
284 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
285 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
286 var n: number = 10 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
287 type A = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
288 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
289 defcompile |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
290 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
291 v9.CheckSourceFailure(lines, 'E1399: Type can only be used in a script', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
292 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
293 # json_encode should fail with a type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
294 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
295 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
296 type A = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
297 var x = json_encode(A) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
298 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
299 v9.CheckSourceFailure(lines, 'E1161: Cannot json encode a typealias', 3) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
300 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
301 # Comparing type alias with a number (script level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
302 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
303 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
304 type A = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
305 var n: number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
306 var x = A == n |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
307 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
308 v9.CheckSourceFailure(lines, 'E1072: Cannot compare typealias with number', 4) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
309 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
310 # Comparing type alias with a number (def function level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
311 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
312 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
313 type A = list<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
314 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
315 var n: number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
316 var x = A == n |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
317 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
318 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
319 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
320 v9.CheckSourceFailure(lines, 'E1072: Cannot compare typealias with number', 2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
321 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
322 # casting a number to a type alias (script level) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
323 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
324 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
325 type MyType = bool |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
326 assert_equal(true, <MyType>1 == true) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
327 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
328 v9.CheckSourceSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
329 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
330 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
331 " Test for exporting and importing type aliases |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
332 def Test_typealias_import() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
333 var lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
334 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
335 export type MyType = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
336 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
337 writefile(lines, 'Xtypeexport.vim', 'D') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
338 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
339 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
340 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
341 import './Xtypeexport.vim' as A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
342 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
343 var myList: A.MyType = [1, 2, 3] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
344 def Foo(l: A.MyType) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
345 assert_equal([1, 2, 3], l) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
346 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
347 Foo(myList) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
348 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
349 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
350 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
351 # Use a non existing type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
352 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
353 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
354 import './Xtypeexport.vim' as A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
355 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
356 var myNum: A.SomeType = 10 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
357 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
358 v9.CheckScriptFailure(lines, 'E1010: Type not recognized: A.SomeType = 10', 4) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
359 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
360 # Use a type alias that is not exported |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
361 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
362 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
363 type NewType = dict<string> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
364 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
365 writefile(lines, 'Xtypeexport2.vim', 'D') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
366 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
367 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
368 import './Xtypeexport2.vim' as A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
369 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
370 var myDict: A.NewType = {} |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
371 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
372 v9.CheckScriptFailure(lines, 'E1049: Item not exported in script: NewType', 4) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
373 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
374 # Using the same name as an imported type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
375 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
376 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
377 export type MyType2 = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
378 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
379 writefile(lines, 'Xtypeexport3.vim', 'D') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
380 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
381 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
382 import './Xtypeexport3.vim' as A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
383 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
384 type MyType2 = A.MyType2 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
385 var myList1: A.MyType2 = [1, 2, 3] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
386 var myList2: MyType2 = [4, 5, 6] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
387 assert_equal([1, 2, 3], myList1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
388 assert_equal([4, 5, 6], myList2) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
389 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
390 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
391 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
392 # Using an exported class to create a type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
393 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
394 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
395 export class MyClass |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
396 var val = 10 |
33687
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
397 endclass |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
398 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
399 writefile(lines, 'Xtypeexport4.vim', 'D') |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
400 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
401 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
402 import './Xtypeexport4.vim' as T |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
403 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
404 type MyType3 = T.MyClass |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
405 var c: MyType3 = MyType3.new() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
406 assert_equal(10, c.val) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
407 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
408 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
409 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
410 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
411 " Test for using typealias as a def function argument and return type |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
412 def Test_typealias_func_argument() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
413 var lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
414 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
415 type A = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
416 def Foo(l: A): A |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
417 assert_equal([1, 2], l) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
418 return l |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
419 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
420 var x: A = [1, 2] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
421 assert_equal([1, 2], Foo(x)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
422 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
423 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
424 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
425 # passing a type alias variable to a function expecting a specific type |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
426 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
427 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
428 type A = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
429 def Foo(l: list<number>) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
430 assert_equal([1, 2], l) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
431 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
432 var x: A = [1, 2] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
433 Foo(x) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
434 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
435 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
436 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
437 # passing a type alias variable to a function expecting any |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
438 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
439 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
440 type A = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
441 def Foo(l: any) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
442 assert_equal([1, 2], l) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
443 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
444 var x: A = [1, 2] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
445 Foo(x) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
446 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
447 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
448 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
449 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
450 " Using a type alias with a builtin function |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
451 def Test_typealias_with_builtin_functions() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
452 var lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
453 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
454 type A = list<func> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
455 assert_equal(0, empty(A)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
456 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
457 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
458 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
459 # Using a type alias with len() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
460 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
461 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
462 type A = list<func> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
463 var x = len(A) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
464 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
465 v9.CheckScriptFailure(lines, 'E701: Invalid type for len()', 3) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
466 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
467 # Using a type alias with len() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
468 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
469 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
470 type A = list<func> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
471 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
472 var x = len(A) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
473 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
474 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
475 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
476 v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list<any> but got typealias', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
477 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
478 # Using a type alias with eval() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
479 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
480 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
481 type A = number |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
482 def Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
483 var x = eval("A") |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
484 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
485 Foo() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
486 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
487 v9.CheckScriptFailure(lines, 'E1403: Type alias "A" cannot be used as a value', 1) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
488 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
489 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
490 " Test for type alias refcount |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
491 def Test_typealias_refcount() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
492 var lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
493 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
494 type A = list<func> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
495 assert_equal(1, test_refcount(A)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
496 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
497 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
498 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
499 lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
500 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
501 type B = list<number> |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
502 var x: B = [] |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
503 assert_equal(1, test_refcount(B)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
504 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
505 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
506 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
507 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
508 " Test for using instanceof() with a type alias |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
509 def Test_typealias_instanceof() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
510 var lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
511 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
512 class C |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
513 endclass |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
514 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
515 type Ctype = C |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
516 var o = C.new() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
517 assert_equal(1, instanceof(o, Ctype)) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
518 type Ntype = number |
33924
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
519 assert_fails('instanceof(o, Ntype)', 'E693: Class or class typealias required for argument 2') |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
520 assert_fails('instanceof(o, Ctype, Ntype)', 'E693: Class or class typealias required for argument 3') |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
521 |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
522 def F() |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
523 var x = instanceof(o, Ntype) |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
524 enddef |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
525 assert_fails('F()', 'E693: Class or class typealias required for argument 2') |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
526 |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
527 def G(): bool |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
528 return instanceof(o, Ctype) |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
529 enddef |
ccdb948c7273
patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents:
33913
diff
changeset
|
530 assert_equal(1, G()) |
33687
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
531 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
532 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
533 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
534 |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
535 " Test for type aliasing a class |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
536 def Test_typealias_class() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
537 var lines =<< trim END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
538 vim9script |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
539 class C |
33942
3bba09502b8d
patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents:
33936
diff
changeset
|
540 var color = 'green' |
33687
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
541 endclass |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
542 type MyClass = C |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
543 var o: MyClass = MyClass.new() |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
544 assert_equal('green', o.color) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
545 END |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
546 v9.CheckScriptSuccess(lines) |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
547 enddef |
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
548 |
33936
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
549 " Test for typealias as function arg and return value |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
550 def Test_type_as_func_argument_or_return_value() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
551 # check typealias as arg, function call in script level |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
552 var lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
553 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
554 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
555 def Foo(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
556 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
557 Foo(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
558 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
559 v9.CheckScriptFailure(lines, 'E1403: Type alias "A" cannot be used as a value', 5) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
560 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
561 # check typealias as function return, function call in script level |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
562 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
563 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
564 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
565 def Foo(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
566 return A |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
567 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
568 Foo() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
569 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
570 v9.CheckScriptFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
571 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
572 # check typealias as arg, function call in :def |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
573 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
574 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
575 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
576 def Foo(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
577 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
578 def F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
579 Foo(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
580 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
581 F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
582 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
583 v9.CheckScriptFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
584 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
585 # check typealias as function return, function call in :def |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
586 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
587 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
588 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
589 def Foo(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
590 return A |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
591 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
592 def F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
593 Foo() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
594 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
595 F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
596 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
597 v9.CheckScriptFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
598 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
599 # check funcref using typealias as arg at script level |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
600 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
601 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
602 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
603 def F(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
604 echo typename(arg) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
605 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
606 var Fref: func(any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
607 Fref = F |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
608 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
609 Fref(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
610 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
611 v9.CheckScriptFailure(lines, 'E1403: Type alias "A" cannot be used as a value', 9) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
612 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
613 # check funcref using typealias as arg in :def |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
614 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
615 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
616 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
617 def F(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
618 echo typename(arg) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
619 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
620 var Fref: func(any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
621 Fref = F |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
622 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
623 def G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
624 Fref(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
625 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
626 G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
627 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
628 v9.CheckScriptFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
629 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
630 # check funcref using typealias as return |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
631 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
632 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
633 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
634 def F(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
635 return A |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
636 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
637 var Fref: func(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
638 Fref = F |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
639 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
640 Fref() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
641 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
642 v9.CheckScriptFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
643 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
644 # check defered function using typealias as arg |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
645 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
646 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
647 type A = number |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
648 def F(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
649 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
650 def G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
651 defer F(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
652 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
653 G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
654 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
655 v9.CheckScriptFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
656 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
657 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
658 " Test for class typealias as function arg and return value |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
659 def Test_class_as_func_argument_or_return_value() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
660 # check class typealias as arg, function call in script level |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
661 var lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
662 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
663 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
664 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
665 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
666 def Foo(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
667 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
668 Foo(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
669 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
670 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 7) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
671 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
672 # check class typealias as function return, function call in script level |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
673 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
674 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
675 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
676 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
677 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
678 def Foo(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
679 return A |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
680 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
681 Foo() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
682 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
683 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
684 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
685 # check class typealias as arg, function call in :def |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
686 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
687 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
688 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
689 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
690 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
691 def Foo(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
692 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
693 def F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
694 Foo(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
695 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
696 F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
697 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
698 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
699 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
700 # check class typealias as function return, function call in :def |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
701 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
702 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
703 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
704 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
705 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
706 def Foo(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
707 return A |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
708 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
709 def F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
710 Foo() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
711 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
712 F() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
713 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
714 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
715 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
716 # check funcref using class typealias as arg at script level |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
717 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
718 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
719 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
720 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
721 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
722 def F(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
723 echo typename(arg) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
724 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
725 var Fref: func(any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
726 Fref = F |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
727 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
728 Fref(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
729 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
730 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 11) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
731 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
732 # check funcref using class typealias as arg in :def |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
733 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
734 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
735 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
736 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
737 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
738 def F(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
739 echo typename(arg) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
740 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
741 var Fref: func(any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
742 Fref = F |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
743 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
744 def G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
745 Fref(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
746 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
747 G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
748 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
749 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
750 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
751 # check funcref using class typealias as return |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
752 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
753 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
754 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
755 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
756 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
757 def F(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
758 return A |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
759 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
760 var Fref: func(): any |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
761 Fref = F |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
762 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
763 Fref() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
764 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
765 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
766 |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
767 # check defered function using class typealias as arg |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
768 lines =<< trim END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
769 vim9script |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
770 class C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
771 endclass |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
772 type A = C |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
773 def F(arg: any) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
774 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
775 def G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
776 defer F(A) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
777 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
778 G() |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
779 END |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
780 v9.CheckScriptFailure(lines, 'E1405: Class "C" cannot be used as a value', 1) |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
781 enddef |
bdd408288d95
patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents:
33933
diff
changeset
|
782 |
33687
9a932ba43f6e
patch 9.0.2080: vim9_script test too large
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
783 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker |