bugGNU Octave - Bugs: bug #61676, Assigning classdef objects to...

 
 

bug #61676: Assigning classdef objects to other types does not call converter methods

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Wed 15 Dec 2021 03:37:49 AM UTC
   
 
Category:  Classdef Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 15 Dec 2021 03:37:49 AM UTC, original submission:  

as initially discussed at
https://octave.discourse.group/t/assigning-classdef-objects-to-other-types-does-not-automatically-call-existing-converter-methods


A = [1:5];
B = myclass
A(4) = B


according to expected matlab behavior, Octave should first look to myclass for a method the same name as the class of A, absent that it should pass B to A's constructor to see if it can handle a myclass object, otherwise it should error.

Trying a test class:


classdef myclass
  properties
    ## no properties
  endproperties

  methods (Access = public)
    function this = myclass (varargin)
      if (nargin != 0 )
        error ("Invalid call");
      endif
    endfunction
  endmethods

  methods (Access = public)
    function retval = double (this)
      retval = NaN;
    endfunction
  endmethods
endclassdef



this should work as a converter to replace A(4) with NaN, however I instead get:


however I instead get:

>> A(4)=B
error: operator =: no conversion for assignment of 'object' to indexed 'matrix'


the only similar bug I see is an old closed bug #32651. it seems that was before classdef, but described a similar sounding issue with method precedence, where Octave "follows Mathwork's published function precedence whereas Matlab does not" preventing Octave from ever calling converter functions.

Maybe the fix here can borrow from what was learned there?

Nicholas Jankowski <nrjank>
Group Member

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Carbon-Copy List
  • -email is unavailable- added by nrjank (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-05-16 nrjank CategoryOctave Function Classdef
    2021-12-16 nrjank Dependencies- patch #10102 is dependent
    2021-12-15 nrjank Summaryclassdef converter methods are not called Assigning classdef objects to other types does not call converter methods

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code