bugGNU Octave - Bugs: bug #59590, arguments not passed to indirectly...

 
 

bug #59590: arguments not passed to indirectly inherited constructor

Submitted by:  Ray Zimmerman <rdzman>
Submitted on:  Tue 01 Dec 2020 10:07:04 PM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
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.

 

Sat 05 Dec 2020 07:56:47 PM UTC, comment #1: 

Confirmed.  Changing priority to low since there are simple workarounds (explicit constructors for all intermediate classes OR calling desired parent class constructor directly).  These workarounds also produce code that will run in either Matlab or Octave so there is no penalty to coding in this style.

I also changed the release to dev and the OS to any.  It is a Matlab incompatibility and it would be nice to fix this, but not on the stable branch of Octave.

Rik <rik5>
Project Administrator
Tue 01 Dec 2020 10:07:04 PM UTC, original submission:  

Suppose we have the following set of classdef classes, whre classC inherits from classB which in turn inherits from classA. The constructor for classC calls its parent with the same arguments, but the intermediate classB does not have an explicit constructor. In this case, arguments passed to the constructor for classC will not be passed to the constructor for classA in Octave, though they are in Matlab.

classdef classA < handle
    methods
        function obj = classA(varargin)
            fprintf('--> classA() called with %d args\n', nargin);
        end
    end
end

classdef classB < classA
end

classdef classC < classB
    methods
        function obj = classC(varargin)
            fprintf('--> classC() called with %d args\n', nargin);
            obj@classB(varargin{:});
        end
    end
end

The result in Octave is ...

> c = classC(1,2,3);
--> classC() called with 3 args
--> classA() called with 0 args

The result in Matlab R2018a (9.4) and later is ...

>> c = classC(1,2,3);
--> classC() called with 3 args
--> classA() called with 3 args

I should note that in Matlab R2017b (9.3) and earlier, this results in an error ...

>> c = classC(1,2,3);
--> classC() called with 3 args
Error using classB
Too many input arguments.

Error in classC (line 5)
            obj@classB(varargin{:});

My current workaround is to avoid calling constructors that are not explicitly defined, either by including an explicit constructor in intermediate classes, e.g. classB, or by having the classC constructor call the classA constructor explicitly.

Ray Zimmerman <rdzman>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by rdzman (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-12-05 rik5 Priority5 - Normal => 3 - Low
        StatusNone => Confirmed
        Release6.0.90 => dev
        Operating SystemMac OS => Any

    Back to the top


    Powered by Savane 3.7