END
v9.CheckScriptFailure(lines, 'E1010:')
+ # Test for setting a member on a null object
+ lines =<< trim END
+ vim9script
+ class A
+ this.val: string
+ endclass
+
+ def F()
+ var obj: A
+ obj.val = ""
+ enddef
+ F()
+ END
+ v9.CheckScriptFailure(lines, 'E1360: Using a null object')
+
+ # Test for accessing a member on a null object
+ lines =<< trim END
+ vim9script
+ class A
+ this.val: string
+ endclass
+
+ def F()
+ var obj: A
+ echo obj.val
+ enddef
+ F()
+ END
+ v9.CheckScriptFailure(lines, 'E1360: Using a null object')
+
+ # Test for setting a member on a null object, at script level
+ lines =<< trim END
+ vim9script
+ class A
+ this.val: string
+ endclass
+
+ var obj: A
+ obj.val = ""
+ END
+ # FIXME(in source): this should give E1360 as well!
+ v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<A> but got string')
+
+ # Test for accessing a member on a null object, at script level
+ lines =<< trim END
+ vim9script
+ class A
+ this.val: string
+ endclass
+
+ var obj: A
+ echo obj.val
+ END
+ v9.CheckScriptFailure(lines, 'E1360: Using a null object')
+
# Test for no space before or after the '=' when initializing a member
# variable
lines =<< trim END
// -1 dict, list, blob or object
tv = STACK_TV_BOT(-3);
SOURCING_LNUM = iptr->isn_lnum;
- if (dest_type == VAR_ANY)
+
+ // Make sure an object has been initialized
+ if (dest_type == VAR_OBJECT && tv_dest->vval.v_object == NULL)
+ {
+ emsg(_(e_using_null_object));
+ status = FAIL;
+ }
+ else if (dest_type == VAR_ANY)
{
dest_type = tv_dest->v_type;
if (dest_type == VAR_DICT)