changeset 27056:64461ccf3039

allow inherited method calls during classdef construction (bug #52614) * cdef-object.cc (cdef_object_scalar::is_partially_constructed_for): When iterating over ctor_list, call is_partially_constructed_for instead of is_constructed_for. * test/classdef/class_bug52614A.m, test/classdef/class_bug52614B.m: New files. * test/classdef/module.mk: Update. * test/classdef/classdef.tst: New test.
author John W. Eaton <jwe@octave.org>
date Fri, 19 Apr 2019 12:38:13 +0000
parents b38807a23fd2
children 986128cf1e07
files libinterp/octave-value/cdef-object.cc test/classdef/class_bug52614A.m test/classdef/class_bug52614B.m test/classdef/classdef.tst test/classdef/module.mk
diffstat 5 files changed, 46 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/cdef-object.cc	Fri Apr 19 13:30:51 2019 +0200
+++ b/libinterp/octave-value/cdef-object.cc	Fri Apr 19 12:38:13 2019 +0000
@@ -724,16 +724,17 @@
   bool
   cdef_object_scalar::is_partially_constructed_for (const cdef_class& cls) const
   {
-    std::map< cdef_class, std::list<cdef_class>>::const_iterator it;
-
     if (is_constructed ())
       return true;
-    else if ((it = ctor_list.find (cls)) == ctor_list.end ()
-             || it->second.empty ())
+
+    std::map<cdef_class, std::list<cdef_class>>::const_iterator it
+      = ctor_list.find (cls);
+
+    if (it == ctor_list.end () || it->second.empty ())
       return true;
 
     for (const auto& cdef_cls : it->second)
-      if (! is_constructed_for (cdef_cls))
+      if (! is_partially_constructed_for (cdef_cls))
         return false;
 
     return true;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/classdef/class_bug52614A.m	Fri Apr 19 12:38:13 2019 +0000
@@ -0,0 +1,15 @@
+classdef class_bug52614A < handle
+  properties
+    a
+  end
+
+  methods
+    function obj = class_bug52614A ()
+      obj.foo ();
+    end
+
+    function foo (obj)
+      obj.a = 1;
+    end
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/classdef/class_bug52614B.m	Fri Apr 19 12:38:13 2019 +0000
@@ -0,0 +1,16 @@
+classdef class_bug52614B < class_bug52614A
+  properties
+    b
+  end
+
+  methods
+    function obj = class_bug52614B ()
+      obj = obj@class_bug52614A ();
+    end
+
+    function foo (obj)
+      foo@class_bug52614A (obj);
+      obj.b = 2;
+    end
+  end
+end
--- a/test/classdef/classdef.tst	Fri Apr 19 13:30:51 2019 +0200
+++ b/test/classdef/classdef.tst	Fri Apr 19 12:38:13 2019 +0000
@@ -186,3 +186,10 @@
 %! assert (isequal (obj{1:2}(1:2), ones (2)));
 %! obj{3:4}(3:4) = 4 * ones (2);
 %! assert (isequal (obj{3:4}(3:4), 4 * ones (2)));
+
+%!test <52614>
+%! A = class_bug52614A ();
+%! assert (A.a, 1);
+%! B = class_bug52614B ();
+%! assert (B.a, 1);
+%! assert (B.b, 2);
--- a/test/classdef/module.mk	Fri Apr 19 13:30:51 2019 +0200
+++ b/test/classdef/module.mk	Fri Apr 19 12:38:13 2019 +0000
@@ -1,4 +1,6 @@
 classdef_TEST_FILES = \
+  %reldir%/class_bug52614A.m \
+  %reldir%/class_bug52614B.m \
   %reldir%/classdef.tst \
   %reldir%/foo_method_changes_property_size.m \
   %reldir%/foo_static_method_constant_property.m \