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

 
 

bug #59590: arguments not passed to indirectly inherited constructor

Submitter:  Ray Zimmerman <rdzman>
Submitted:  Tue 01 Dec 2020 10:07:04 PM UTC
   
 
Category:  Classdef 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
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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 mmuetzel (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by rdzman (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-23 mmuetzel CategoryInterpreter Classdef
    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.13-f8d8.
    Corresponding source code