bugGNU Octave - Bugs: bug #60181, Incompatibilities with set methods...

 
 

bug #60181: Incompatibilities with set methods of classdef handle classes

Submitter:  Markus Mützel <mmuetzel>
Submitted:  Sat 06 Mar 2021 01:17:37 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  None 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 06 Mar 2021 01:17:37 PM UTC, original submission:  

In bug #60143, the following behavior of classdef set-methods was observed with the attached classes in Matlab R2020b:

>> a = bug60143_value;
>> a.t = 4
The set function for property 't' must return an instance of class 'bug60143_value'.

>> a.u = 3
method set.u

a =

  bug60143_value with properties:

    t: []
    u: 3

>> b = bug60143_handle;
>> b.t = 2
method set.t
In set function for property 't', the class of the output object is 'double'; the class of the input object is 'bug60143_handle'. They should be the same.

>> b.u = 4
method set.u

b =

  bug60143_handle with properties:

    t: []
    u: 4


The syntax highlighter in its editor marks the set function for u in class `bug60143_value` with an error highlight "Set Methods must have at most one output.". But -- surprisingly -- it still seems to work (ignoring the extra output).

It looks like it is possible that a set function of a handle class returns a different instance of the same class. That's interesting. I didn't know this was possible.

With Octave 7 (hg id 65979d33f147), I see the following:

>> a = bug60143_value;

>> a.t = 4

error: set.t: function called with too many outputs
error: called from
    set.t
>> a.u = 3

method set.u
a =

  bug60143_value object with properties:

      t: [0x0 double]
      u: [1x1 double]

>> b = bug60143_handle;

>> b.t = 2

method set.t
b =

  bug60143_handle object with properties:

      t: [1x1 double]
      u: [0x0 double]

>> b.u = 4
[snip]
method set.u
method set.u
method set.u
method set.u
method set.u
method set.u
method set.u
error: max_recursion_depth exceeded
error: called from
    set.u
    set.u at line 21 column 11


The results with the value class look like they are compatible.

But the behavior of the handle class is different:
It looks like we should not discard the return value of the set-method. One return value seems to be ok. But the type of the return value must match the class.
Additionally, it looks like a set-method should not be able to call itself even if the used object is a different instance of the same class (or whatever the exact condition is).

Markus Mützel <mmuetzel>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #51009:  bug60143_value.m added by mmuetzel (270B - text/plain)
file #51010:  bug60143_handle.m added by mmuetzel (348B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (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
    2024-01-23 mmuetzel CategoryInterpreter Classdef
    2021-03-06 mmuetzel Attached File- Added bug60143_value.m, #51009
        Attached File- Added bug60143_handle.m, #51010

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code