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

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

[Octave-bug-tracker] [bug #61676] classdef converter methods are not cal


From: Nicholas Jankowski
Subject: [Octave-bug-tracker] [bug #61676] classdef converter methods are not called
Date: Tue, 14 Dec 2021 22:37:51 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0

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

                 Summary: classdef converter methods are not called
                 Project: GNU Octave
            Submitted by: nrjank
            Submitted on: Tue 14 Dec 2021 10:37:49 PM EST
                Category: Octave Function
                Severity: 2 - Minor
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: Nicholas Jankowski
        Originator Email: 
             Open/Closed: Open
                 Release: dev
         Discussion Lock: Any
        Operating System: Any

    _______________________________________________________

Details:

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?




    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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