bugGNU Octave - Bugs: bug #48693, classdef subsref method is not...

 
 

bug #48693: classdef subsref method is not called with correct nargout value

Submitter:  Mike Miller <mtmiller>
Submitted:  Wed 03 Aug 2016 10:02:56 PM UTC
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Patch Submitted Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

Sat 05 Jun 2021 08:50:20 PM UTC, comment #2: 

Oops, I forgot the file! bug48693.patch

(file #51519)

Fernando <tutissanalio>
Sat 05 Jun 2021 08:45:34 PM UTC, comment #1: 

Here is a candidate patch that solves the issue. Basically, I just copied a few lines of code from the method octave_class:subsref to the method octave_classdef::subsref.

Fernando <tutissanalio>
Wed 03 Aug 2016 10:02:56 PM UTC, original submission:  

In a classdef handle class, the subsref method is supposed to be called with `nargout` set to the number of values that the indexing argument addresses.

This works for old-style struct-based classes, but not for classdef classes.

Given the following constructor

classdef foo < handle
endclassdef

and the following simple definition of subsref

function varargout = subsref (x, idx)
  varargout = num2cell (zeros (size (idx(1).subs{1})));
endfunction

Then the following only returns a single value, even though the indexing operation is over a range of 10 values, and nargout should be set accordingly to capture 10 values:

>> x = foo;
>> x{1:10}
ans = 0
>> y = {x{1:10}}
y =
{
  [1,1] = 0
}

but, assigning to the right number of output values gets the correct output

[y{1:10}] = x{1:10}

If foo is changed to be a struct-based class with the following constructor, but the subsref method is left exactly the same,

function y = foo ()
  y = class (struct (), "foo");
endfunction

then nargout is set correctly and the indexing examples work as expected.

This is a difference in how subsref is implemented in the octave_class vs octave_classdef classes.

Mike Miller <mtmiller>
Project Administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #51519:  bug48693.patch added by tutissanalio (3KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by nrjank (Updated the item)
  • -email is unavailable- added by tutissanalio (Posted a comment)
  •  

    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 project members can vote.

     

     

     

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-09-08 nrjank StatusNone Patch Submitted
    2021-06-05 tutissanalio Attached File- Added bug48693.patch, #51519
    2019-02-26 mtmiller Carbon-CopyRemoved 80942 -

    Back to the top


    Powered by Savane 3.9