Mercurial > vim
comparison src/testdir/test_vim9_typealias.vim @ 34006:ab6a70fad5b5 v9.0.2184
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Commit: https://github.com/vim/vim/commit/e75fde6b043371a188660c3423e48b1b7fd7e14b
Author: Ernie Rael <errael@raelity.com>
Date: Thu Dec 21 17:18:54 2023 +0100
patch 9.0.2184: Vim9: inconsistent :type/:class messages
Problem: Vim9: inconsistent :type/:class messages
Solution: Update the Messages (Ernie Rael)
closes: #13706
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 21 Dec 2023 17:30:05 +0100 |
parents | 84b93d95a952 |
children | be4389b04043 |
comparison
equal
deleted
inserted
replaced
34005:f5c639a69421 | 34006:ab6a70fad5b5 |
---|---|
16 assert_equal(['a', 'b'], b) | 16 assert_equal(['a', 'b'], b) |
17 assert_equal(['e', 'f'], Foo(['e', 'f'])) | 17 assert_equal(['e', 'f'], Foo(['e', 'f'])) |
18 assert_equal('typealias<list<string>>', typename(ListOfStrings)) | 18 assert_equal('typealias<list<string>>', typename(ListOfStrings)) |
19 assert_equal(v:t_typealias, type(ListOfStrings)) | 19 assert_equal(v:t_typealias, type(ListOfStrings)) |
20 assert_equal('ListOfStrings', string(ListOfStrings)) | 20 assert_equal('ListOfStrings', string(ListOfStrings)) |
21 assert_equal(false, null == ListOfStrings) | 21 assert_fails('var x = null == ListOfStrings', 'E1403: Type alias "ListOfStrings" cannot be used as a value') |
22 END | 22 END |
23 v9.CheckSourceSuccess(lines) | 23 v9.CheckSourceSuccess(lines) |
24 | 24 |
25 # Use type alias at def function level | 25 # Use type alias at def function level |
26 lines =<< trim END | 26 lines =<< trim END |
34 assert_equal(['c', 'd'], c) | 34 assert_equal(['c', 'd'], c) |
35 assert_equal(['e', 'f'], Foo(['e', 'f'])) | 35 assert_equal(['e', 'f'], Foo(['e', 'f'])) |
36 assert_equal('typealias<list<string>>', typename(ListOfStrings)) | 36 assert_equal('typealias<list<string>>', typename(ListOfStrings)) |
37 assert_equal(v:t_typealias, type(ListOfStrings)) | 37 assert_equal(v:t_typealias, type(ListOfStrings)) |
38 assert_equal('ListOfStrings', string(ListOfStrings)) | 38 assert_equal('ListOfStrings', string(ListOfStrings)) |
39 assert_equal(false, null == ListOfStrings) | 39 #assert_equal(false, null == ListOfStrings) |
40 enddef | 40 enddef |
41 Bar() | 41 Bar() |
42 END | 42 END |
43 v9.CheckSourceSuccess(lines) | 43 v9.CheckSourceSuccess(lines) |
44 | 44 |
199 lines =<< trim END | 199 lines =<< trim END |
200 vim9script | 200 vim9script |
201 type MyType = list<number> | 201 type MyType = list<number> |
202 MyType = [1, 2, 3] | 202 MyType = [1, 2, 3] |
203 END | 203 END |
204 v9.CheckSourceFailure(lines, 'E1395: Type alias "MyType" cannot be modified', 3) | 204 v9.CheckSourceFailure(lines, 'E1403: Type alias "MyType" cannot be used as a value', 3) |
205 | 205 |
206 # Assigning a type alias (def function level) | 206 # Assigning a type alias (def function level) |
207 lines =<< trim END | 207 lines =<< trim END |
208 vim9script | 208 vim9script |
209 type A = list<string> | 209 type A = list<string> |
217 # Using type alias in an expression (script level) | 217 # Using type alias in an expression (script level) |
218 lines =<< trim END | 218 lines =<< trim END |
219 vim9script | 219 vim9script |
220 type MyType = list<number> | 220 type MyType = list<number> |
221 assert_fails('var m = MyType', 'E1403: Type alias "MyType" cannot be used as a value') | 221 assert_fails('var m = MyType', 'E1403: Type alias "MyType" cannot be used as a value') |
222 assert_fails('var i = MyType + 1', 'E1400: Using type alias "MyType" as a Number') | 222 assert_fails('var i = MyType + 1', 'E1403: Type alias "MyType" cannot be used as a value') |
223 assert_fails('var f = 1.0 + MyType', 'E1400: Using type alias "MyType" as a Number') | 223 assert_fails('var f = 1.0 + MyType', 'E1403: Type alias "MyType" cannot be used as a value') |
224 assert_fails('MyType += 10', 'E1395: Type alias "MyType" cannot be modified') | 224 assert_fails('MyType += 10', 'E1403: Type alias "MyType" cannot be used as a value') |
225 assert_fails('var x = $"-{MyType}-"', 'E1402: Using type alias "MyType" as a String') | 225 assert_fails('var x = $"-{MyType}-"', 'E1403: Type alias "MyType" cannot be used as a value') |
226 assert_fails('var x = MyType[1]', 'E909: Cannot index a special variable') | 226 assert_fails('var x = MyType[1]', 'E1403: Type alias "MyType" cannot be used as a value') |
227 END | 227 END |
228 v9.CheckSourceSuccess(lines) | 228 v9.CheckSourceSuccess(lines) |
229 | 229 |
230 # Using type alias in an expression (def function level) | 230 # Using type alias in an expression (def function level) |
231 lines =<< trim END | 231 lines =<< trim END |
234 def Foo() | 234 def Foo() |
235 var x = MyType + 1 | 235 var x = MyType + 1 |
236 enddef | 236 enddef |
237 Foo() | 237 Foo() |
238 END | 238 END |
239 v9.CheckSourceFailure(lines, 'E1051: Wrong argument type for +', 1) | 239 v9.CheckSourceFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 1) |
240 | 240 |
241 # Using type alias in an expression (def function level) | 241 # Using type alias in an expression (def function level) |
242 lines =<< trim END | 242 lines =<< trim END |
243 vim9script | 243 vim9script |
244 type MyType = list<number> | 244 type MyType = list<number> |
303 vim9script | 303 vim9script |
304 type A = list<string> | 304 type A = list<string> |
305 var n: number | 305 var n: number |
306 var x = A == n | 306 var x = A == n |
307 END | 307 END |
308 v9.CheckSourceFailure(lines, 'E1072: Cannot compare typealias with number', 4) | 308 v9.CheckSourceFailure(lines, 'E1403: Type alias "A" cannot be used as a value', 4) |
309 | 309 |
310 # Comparing type alias with a number (def function level) | 310 # Comparing type alias with a number (def function level) |
311 lines =<< trim END | 311 lines =<< trim END |
312 vim9script | 312 vim9script |
313 type A = list<string> | 313 type A = list<string> |
315 var n: number | 315 var n: number |
316 var x = A == n | 316 var x = A == n |
317 enddef | 317 enddef |
318 Foo() | 318 Foo() |
319 END | 319 END |
320 v9.CheckSourceFailure(lines, 'E1072: Cannot compare typealias with number', 2) | 320 v9.CheckSourceFailure(lines, 'E1407: Cannot use a Typealias as a variable or value', 2) |
321 | 321 |
322 # casting a number to a type alias (script level) | 322 # casting a number to a type alias (script level) |
323 lines =<< trim END | 323 lines =<< trim END |
324 vim9script | 324 vim9script |
325 type MyType = bool | 325 type MyType = bool |