patch 9.0.1932: Vim9: error when using null object constructor

Problem:  Vim9: error when using null object constructor
Solution: Check for a null object only when calling an object method

closes: #13154
closes: #13163

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 87679d8..87dc536 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -5675,4 +5675,34 @@
   v9.CheckSourceSuccess(lines)
 enddef
 
+" The following test was failing after 9.0.1914.  This was caused by using a
+" freed object from a previous method call.
+def Test_freed_object_from_previous_method_call()
+  var lines =<< trim END
+    vim9script
+
+    class Context
+    endclass
+
+    class Result
+    endclass
+
+    def Failure(): Result
+      return Result.new()
+    enddef
+
+    def GetResult(ctx: Context): Result
+      return Failure()
+    enddef
+
+    def Test_GetResult()
+      var ctx = Context.new()
+      var result = GetResult(ctx)
+    enddef
+
+    Test_GetResult()
+  END
+  v9.CheckSourceSuccess(lines)
+enddef
+
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker