bugGNU Octave - Bugs: bug #51534, Invoking parent class constructor...

 
 

bug #51534: Invoking parent class constructor in child constructor fails

Submitter:  Piotr Held <jsoh425>
Submitted:  Sat 22 Jul 2017 12:05:52 AM UTC
   
 
Category:  Interpreter Severity:  4 - Important
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Piotr Held Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 09 Aug 2017 03:39:17 PM UTC, comment #7: 

I made a small tweak to the test code to use double quotes rather than single quotes to conform to Octave coding recommendations (http://hg.savannah.gnu.org/hgweb/octave/rev/12203140139f).

The tests now pass for me so I'm going to mark this as fixed and close the report.

Rik <rik5>
Group administrator
Tue 08 Aug 2017 11:10:48 PM UTC, comment #6: 

With a few minor edits, I pushed your changeset here:

http://hg.savannah.gnu.org/hgweb/octave/rev/ff893e26aeeb

I'm not sure whether a check is needed.

Thanks also for adding tests.

John W. Eaton <jwe>
Group administrator
Tue 08 Aug 2017 06:44:09 PM UTC, comment #5: 

I created a patch, which doesn't have to be final. My main question is: should the new code (past the &quot;if else&quot;) statement actually include a check if the called function is a superclass constructor?

I kind of assume that through the great siv that is tree_evaluator::visit_index_expression everything else would have been dealt with. If you guys think that I should include a check for calling the superclass then I'll do that. If you think it should be called somewhere else, then I'm open to that as well. If yes, then my question is: where?

I also included tests for the problem.

(file #41455)

Piotr Held <jsoh425>
Mon 07 Aug 2017 09:37:43 PM UTC, comment #4: 

Coming back late to this report, but I now understand what is supposed to happen and can confirm that Octave is in error.

Rik <rik5>
Group administrator
Mon 24 Jul 2017 06:29:07 PM UTC, comment #3: 

On rev 2641a0196176, this is still not working.

To be clear, with my modification, there is no error message, but the Parent_Class constructor is still not called. Using the following definitions:


classdef Parent_Class
  properties
    val
  end
  methods
    function self = Parent_Class(val)
      self.val = val;
    end
  end
end

classdef Child_Class < Parent_Class
  methods
    function self = Child_Class(val)
      self@Parent_Class(val);
    end
  end
end


the property val is undefined after constructing a Child_Class object.

Mike Miller <mtmiller>
Group Member
Mon 24 Jul 2017 01:09:47 AM UTC, comment #2: 

Could you repeat the test with Mike's modification from comment #1 and a cset >= 23784:f864950f837c?

It works for me.  There was a recent fix to calling static class methods which may have made this work again.

Rik <rik5>
Group administrator
Sat 22 Jul 2017 12:20:17 AM UTC, comment #1: 

Confirmed, although this syntax isn't strictly correct. You aren't supposed to overwrite the self object. The base class constructor is supposed to be called as


  function self = Child_Class(val)
    self@Parent_Class(val);
  end


Regardless, it does look like the base class constructor is not being called correctly anymore, this is a regression from the stable branch.

Mike Miller <mtmiller>
Group Member
Sat 22 Jul 2017 12:05:52 AM UTC, original submission:  

When invoking parent class constructor in child constructor the parent constructor is not properly called.

For Parent Class:

classdef Parent_Class
  methods
    function self = Parent_Class(val)
      val;
    end
  end
end


And Child Class:

classdef Child_Class < Parent_Class
  methods
    function self = Child_Class(val)
      self = self@Parent_Class(val);
    end
  end
end


When calling:

Child_Class('asd')


You get:

error: value on right hand side of assignment is undefined
error: called from
    Child_Class at line 4 column 12


Am attaching the test for this problem.

Piotr Held <jsoh425>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #41455:  patch_bug51534_ver1.diff added by jsoh425 (5KiB - text/x-patch)
file #41286:  Invoke_Parent_Constr.tar.gz added by jsoh425 (305B - application/gzip - Tests for the original submission)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by jsoh425 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-09 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2017-08-08 jwe StatusConfirmed Ready For Test
    2017-08-08 jsoh425 Attached File- Added patch_bug51534_ver1.diff, #41455
    2017-07-24 mtmiller StatusWorks For Me Confirmed
    2017-07-24 rik5 StatusConfirmed Works For Me
    2017-07-22 mtmiller CategoryNone Interpreter
    2017-07-22 mtmiller Severity3 - Normal 4 - Important
        StatusNone Confirmed
    2017-07-22 jsoh425 Attached File- Added Invoke_Parent_Constr.tar.gz, #41286

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code