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

 
 

bug #55856: subsref called in a subscripted assignment operation

Submitted by:  Guillaume <gyom>
Submitted on:  Thu 07 Mar 2019 05:40:37 PM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  None Assigned to:  None
Originator Name:  Guillaume 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.

 

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>
Project 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 jwe (Posted a comment)
  • -email is unavailable- added by gyom (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.

     

     

     

    No changes have been made to this item

    Back to the top


    Powered by Savane 3.5