bugGNU Octave - Bugs: bug #52614, setting properties of classdef...

 
 

bug #52614: setting properties of classdef object during construction with inheritance

Submitted by:  Amro <amro_octave>
Submitted on:  Thu 07 Dec 2017 03:56:19 PM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  John W. Eaton <jwe>
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Mon 20 May 2019 10:14:27 PM UTC, comment #6:

Confirmed, that the original issue is resolved and no differences to Matlab R2019a.

I think the remaining question is not easy to answer without a good example and eventually might become clearer in another bug report.

Closing this report.

Kai Torben Ohlhus <siko1056>
Project Member
Fri 19 Apr 2019 01:42:03 PM UTC, comment #5:

I pushed the following changeset.

http://hg.savannah.gnu.org/hgweb/octave/rev/64461ccf3039

I'm not completely sure this is the correct change.  Is the correct question here to ask whether parent classes are also partially constructed or is some other test correct?  In any case, it does appear to fix the problem reported here.

I incorporated your example as a test case, so if my fix is incorrect and causes other problems later, I hope a future fix (if any) will not cause this problem to reappear.

John W. Eaton <jwe>
Project AdministratorIn charge of this item.
Fri 02 Feb 2018 09:16:49 AM UTC, comment #4:
Amro <amro_octave>
Fri 02 Feb 2018 04:55:42 AM UTC, comment #3:

@Nirabhra Tapaswi
not to discourage you, but I don't think this an easy bug for a new contributor...

I imagine you'd have to be pretty familiar with the C++ implementation of "classdef" functionality in Octave. This bug has to do with inheritance, method overriding, and object state during construction.

Then again I could be wrong :)

Amro <amro_octave>
Fri 26 Jan 2018 09:41:15 AM UTC, comment #2:

I am new to contributing to Octave and was searching for easy bugs, can you tell me which file this bug is in?

Nirabhra Tapaswi <barin97>
Wed 27 Dec 2017 08:36:23 PM UTC, comment #1:

Confirmed.  This issue is still present on the development branch.  I have changed the category to Matlab Compatibility.

I lowered the priority by 1 since there is a workaround.

Rik <rik5>
Project Administrator
Thu 07 Dec 2017 03:56:19 PM UTC, original submission:

I have a simple class hierarchy with two classes:

  • In the base class, the constructor calls a method which initializes some properties.
  • In the derived class, I override said method (while still calling the parent method). The constructor also invokes the parent constructor.

Here is a minimal example:

$ cat ClassA.m

classdef ClassA < handle
    properties
        a
    end

    methods
        function obj = ClassA()
            disp('-- ClassA.ClassA')
            obj.foo();
        end

        function foo(obj)
            disp('-- ClassA.foo')
            obj.a = 1;
        end
    end
end

$ cat ClassB.m

classdef ClassB < ClassA
    properties
        b
    end

    methods
        function obj = ClassB()
            disp('-- ClassB.ClassB')
            obj = obj@ClassA();
        end

        function foo(obj)
            disp('-- ClassB.foo')
            foo@ClassA(obj);
            obj.b = 2;
        end
    end
end

This works fine in MATLAB (I'm using R2017a):

>> obj = ClassA()
-- ClassA.ClassA
-- ClassA.foo
obj =
  ClassA with properties:
    a: 1

>> obj = ClassB()
-- ClassB.ClassB
-- ClassA.ClassA
-- ClassB.foo
-- ClassA.foo
obj =
  ClassB with properties:
    b: 2
    a: 1

But it fails in Octave 4.2.1:

>> obj = ClassA()
-- ClassA.ClassA
-- ClassA.foo
obj =
<object ClassA>

>> obj = ClassB()
-- ClassB.ClassB
-- ClassA.ClassA
-- ClassB.foo
-- ClassA.foo
error: cannot reference properties of class `ClassB' for non-constructed object
error: called from
    foo at line 15 column 19
    ClassA at line 9 column 13
    ClassB at line 9 column 17

I did try to incorporate the functionality of the foo method into the constructor (i.e directly set the properties a and b from the respective constructors), and the code does work then (both MATLAB and Octave):

$ cat ClassAA.m ClassBB.m

classdef ClassAA < handle
    properties
        a
    end

    methods
        function obj = ClassAA()
            disp('-- ClassAA')
            obj.a = 1;
        end
    end
end

classdef ClassBB < ClassAA
    properties
        b
    end

    methods
        function obj = ClassBB()
            disp('-- ClassBB')
            obj = obj@ClassAA();
            obj.b = 2;
        end
    end
end

Still, I wanted to report this case... Thanks.

Amro <amro_octave>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by barin97 (Posted a comment)
  • -email is unavailable- added by amro_octave (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-05-20 siko1056 StatusReady For Test => Fixed
        Assigned toNone => jwe
        Open/ClosedOpen => Closed
    2019-04-19 jwe Priority4 => 5 - Normal
        StatusConfirmed => Ready For Test
    2017-12-27 rik5 Carbon-CopyRemoved 72865 => -
    2017-12-27 rik5 Priority5 - Normal => 4
        Item GroupUnexpected Error => Matlab Compatibility
        StatusNone => Confirmed
        Release4.2.1 => dev

    Back to the top


    Powered by Savane 3.4