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>
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index a650cc2..2c6a501 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -337,7 +337,7 @@
var bg: Background # UNINITIALIZED
echo Colorscheme.new(bg).GetBackground()
END
- v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<Background> but got object<Unknown>')
+ v9.CheckScriptFailure(lines, 'E1360:')
# TODO: this should not give an error but be handled at runtime
lines =<< trim END
@@ -359,6 +359,46 @@
v9.CheckScriptFailure(lines, 'E1363:')
enddef
+def Test_null_object_assign_compare()
+ var lines =<< trim END
+ vim9script
+
+ var nullo = null_object
+ def F(): any
+ return nullo
+ enddef
+ assert_equal('object<Unknown>', typename(F()))
+
+ var o0 = F()
+ assert_true(o0 == null_object)
+ assert_true(o0 == null)
+
+ var o1: any = nullo
+ assert_true(o1 == null_object)
+ assert_true(o1 == null)
+
+ def G()
+ var x = null_object
+ enddef
+
+ class C
+ endclass
+ var o2: C
+ assert_true(o2 == null_object)
+ assert_true(o2 == null)
+
+ o2 = null_object
+ assert_true(o2 == null)
+
+ o2 = C.new()
+ assert_true(o2 != null)
+
+ o2 = null_object
+ assert_true(o2 == null)
+ END
+ v9.CheckScriptSuccess(lines)
+enddef
+
def Test_class_member_initializer()
var lines =<< trim END
vim9script