bugGNU Octave - Bugs: bug #55856, subsref called in a subscripted...

 
 

bug #55856: subsref called in a subscripted assignment operation

Submitter:  Guillaume <gyom>
Submitted:  Thu 07 Mar 2019 05:40:37 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Guillaume Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 04 Jun 2021 12:22:25 PM UTC, comment #5: 

Thanks for testing.

Closing as fixed.

Markus Mützel <mmuetzel>
Group administrator
Fri 04 Jun 2021 08:00:58 AM UTC, comment #4: 

Thanks Fernando, I am testing with the current development branch and I confirm this issue has been fixed and Matlab and Octave behave identically. I am not sure when this got fixed but this is great news!
Thank you to whoever fixed this and this report can now be closed.

Guillaume <gyom>
Thu 03 Jun 2021 09:11:08 PM UTC, comment #3: 

@Guillaume, have you tried with a more recent octave version? It works for me in Octave 6.1.0, and also in current stable and development branches. In all cases the result is the same as in Matlab.

Fernando <tutissanalio>
Tue 15 Sep 2020 11:16:29 AM UTC, comment #2: 

¯\(°_o)/¯ with the foo class defined in comment #1, subsref is indeed called in Matlab for f.a(end)=1;


>> f = foo ();
>> f.a = 1;
subsasgn
>> f.a(1)
subsref
ans =
     1
>> f.a(end)
subsref
subsref
ans =
     1
>> f.a(end)=1
subsref
subsasgn
f =
       foo object: 1-by-1


If I define an "end" method like this:


function ind = end(obj, k, n)
  disp ("end");
  ind = 1;
end


the above doesn't change and the new method is only called for:


>> f(end)
end
subsref
ans =
  struct with fields:
    a: 1


Guillaume <gyom>
Tue 15 Sep 2020 04:51:49 AM UTC, comment #1: 

Are there instances where subsref should be called?  For example, if the LHS of the assignment includes "end", maybe like this:


obj.data (end) = 1;


What happens if the class defines an "end" method?

In a case like above, what is responsible for setting things up so that "end" will be called with the correct object and index info?

Does the behavior change if there is a subsref method but no subsasgn method (I hope not)?


John W. Eaton <jwe>
Group administrator
Thu 07 Mar 2019 05:40:37 PM UTC, original submission:  

Define the following class with subsref and subsasgn methods


%%% @foo/foo.m
function obj = foo ()
  obj = struct ("store", []);
  obj = class(obj, 'foo');
end



%%% @foo/subsref.m
function val = subsref (obj, S)
  disp ("subsref");
  val = builtin ("subsref", obj.store, S);
end



%%% @foo/subsasgn.m
function obj = subsasgn (obj, S, val)
  disp ("subsasgn");
  obj.store = builtin ("subsasgn", obj.store, S, val);
end


In Matlab:


>> f = foo ();
>> f.a.b = 1;
subsasgn
>> f.a.b
subsref
ans =
     1


In Octave 5.1 or 6.0:


octave:1> f = foo ();
octave:2> f.a.b = 1;
subsref
error: null_matrix cannot be indexed with .
error: called from
    subsref at line 3 column 7
octave:2> f.a = 1;
subsasgn


I don't think that subsref should be called when evaluating "f.a.b = 1;"

Guillaume <gyom>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by tutissanalio (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by gyom (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 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-06-04 mmuetzel StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-da57.
    Corresponding source code