# HG changeset patch # User John W. Eaton # Date 1555677493 0 # Node ID 64461ccf303961a4a18d02f5a11c7986fbf91867 # Parent b38807a23fd25ceff3cb96883e66f712b60a9510 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. diff -r b38807a23fd2 -r 64461ccf3039 libinterp/octave-value/cdef-object.cc --- 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>::const_iterator it; - if (is_constructed ()) return true; - else if ((it = ctor_list.find (cls)) == ctor_list.end () - || it->second.empty ()) + + std::map>::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; diff -r b38807a23fd2 -r 64461ccf3039 test/classdef/class_bug52614A.m --- /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 diff -r b38807a23fd2 -r 64461ccf3039 test/classdef/class_bug52614B.m --- /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 diff -r b38807a23fd2 -r 64461ccf3039 test/classdef/classdef.tst --- 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); diff -r b38807a23fd2 -r 64461ccf3039 test/classdef/module.mk --- 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 \