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

 
 

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

Submitted by:  Nicholas Jankowski <nrjank>
Submitted on:  Wed 15 Dec 2021 03:37:49 AM UTC  
 
Category:  Octave Function 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

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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)
  •  

    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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    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.7