octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #65037] constructor argument getting lost


From: Ray Zimmerman
Subject: [Octave-bug-tracker] [bug #65037] constructor argument getting lost
Date: Fri, 15 Dec 2023 16:37:17 -0500 (EST)

URL:
  <https://savannah.gnu.org/bugs/?65037>

                 Summary: constructor argument getting lost
                   Group: GNU Octave
               Submitter: rdzman
               Submitted: Fri 15 Dec 2023 09:37:15 PM UTC
                Category: Classdef
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: rdzman
        Originator Email: 
             Open/Closed: Open
                 Release: 8.4.0
         Discussion Lock: Any
        Operating System: Any
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Fri 15 Dec 2023 09:37:15 PM UTC By: Ray Zimmerman <rdzman>
I encountered a strange bug where an argument passed to a constructor of a
classdef object is getting lost.

I have been able to reproduce it on multiple OSs in versions from 5.2.0 to
8.4.0 with the following minimal working example.

Given these two classes (also attached) ...

classdef mybaseclass
    methods
        function obj = mybaseclass(varargin)
            fprintf('number of constructor arguments = %d\n', nargin);
        end
    end
end

classdef mysubclass < mybaseclass
    methods
        function obj = mysubclass(varargin)
            obj@mybaseclass(varargin{:});
        end
    end
end


This code ...

b = mybaseclass('baseclass_arg');
s = mysubclass('subclass_arg');
b2 = mybaseclass(b);
b3 = mybaseclass(s);


... outputs ...

number of constructor arguments = 1
number of constructor arguments = 1
number of constructor arguments = 1
number of constructor arguments = 0


The last case should also see 1 argument (as MATLAB does, btw), but it's
missing.

>From my testing, it appears that if any of the arguments to a constructor is
an object of a subclass, it will eat the first argument passed in (even if the
subclassed object is not the first argument).

Any workarounds appreciated ... I need to be able to pass that subclassed
object to the constructor of a parent class object.






    _______________________________________________________
File Attachments:


-------------------------------------------------------
Date: Fri 15 Dec 2023 09:37:15 PM UTC  Name: mybaseclass.m  Size: 173B   By:
rdzman

<http://savannah.gnu.org/bugs/download.php?file_id=55455>
-------------------------------------------------------
Date: Fri 15 Dec 2023 09:37:15 PM UTC  Name: constructor_bug.m  Size: 108B  
By: rdzman

<http://savannah.gnu.org/bugs/download.php?file_id=55456>
-------------------------------------------------------
Date: Fri 15 Dec 2023 09:37:15 PM UTC  Name: mysubclass.m  Size: 156B   By:
rdzman

<http://savannah.gnu.org/bugs/download.php?file_id=55457>

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?65037>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]