Mercurial > vim
comparison src/testdir/test_vim9_class.vim @ 33008:ba1b40b520e8 v9.0.1796
patch 9.0.1796: Vim9 problems with null_objects
Commit: https://github.com/vim/vim/commit/5c018bee0e1e272774584cfb1577327fbb67254a
Author: Ernie Rael <errael@raelity.com>
Date: Sun Aug 27 18:40:26 2023 +0200
patch 9.0.1796: Vim9 problems with null_objects
Problem: Vim9 problems with null_objects
Solution: Vim9 improve null_object usage
Fix "xvar == null", where xvar might have been assigned null_object.
Fix compilation failure: "var o2: C = null_object".
closes: #12890
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 27 Aug 2023 18:45:08 +0200 |
parents | 75c283beb74f |
children | 04c75e67ca30 |
comparison
equal
deleted
inserted
replaced
33007:e7561ca6e020 | 33008:ba1b40b520e8 |
---|---|
335 endclass | 335 endclass |
336 | 336 |
337 var bg: Background # UNINITIALIZED | 337 var bg: Background # UNINITIALIZED |
338 echo Colorscheme.new(bg).GetBackground() | 338 echo Colorscheme.new(bg).GetBackground() |
339 END | 339 END |
340 v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<Background> but got object<Unknown>') | 340 v9.CheckScriptFailure(lines, 'E1360:') |
341 | 341 |
342 # TODO: this should not give an error but be handled at runtime | 342 # TODO: this should not give an error but be handled at runtime |
343 lines =<< trim END | 343 lines =<< trim END |
344 vim9script | 344 vim9script |
345 | 345 |
355 obj.Method1() | 355 obj.Method1() |
356 enddef | 356 enddef |
357 Func() | 357 Func() |
358 END | 358 END |
359 v9.CheckScriptFailure(lines, 'E1363:') | 359 v9.CheckScriptFailure(lines, 'E1363:') |
360 enddef | |
361 | |
362 def Test_null_object_assign_compare() | |
363 var lines =<< trim END | |
364 vim9script | |
365 | |
366 var nullo = null_object | |
367 def F(): any | |
368 return nullo | |
369 enddef | |
370 assert_equal('object<Unknown>', typename(F())) | |
371 | |
372 var o0 = F() | |
373 assert_true(o0 == null_object) | |
374 assert_true(o0 == null) | |
375 | |
376 var o1: any = nullo | |
377 assert_true(o1 == null_object) | |
378 assert_true(o1 == null) | |
379 | |
380 def G() | |
381 var x = null_object | |
382 enddef | |
383 | |
384 class C | |
385 endclass | |
386 var o2: C | |
387 assert_true(o2 == null_object) | |
388 assert_true(o2 == null) | |
389 | |
390 o2 = null_object | |
391 assert_true(o2 == null) | |
392 | |
393 o2 = C.new() | |
394 assert_true(o2 != null) | |
395 | |
396 o2 = null_object | |
397 assert_true(o2 == null) | |
398 END | |
399 v9.CheckScriptSuccess(lines) | |
360 enddef | 400 enddef |
361 | 401 |
362 def Test_class_member_initializer() | 402 def Test_class_member_initializer() |
363 var lines =<< trim END | 403 var lines =<< trim END |
364 vim9script | 404 vim9script |