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

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

[Octave-bug-tracker] [bug #48656] overridden class subsref method may ge


From: Mike Miller
Subject: [Octave-bug-tracker] [bug #48656] overridden class subsref method may get wrong value for nargout
Date: Thu, 28 Jul 2016 21:44:09 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0

URL:
  <http://savannah.gnu.org/bugs/?48656>

                 Summary: overridden class subsref method may get wrong value
for nargout
                 Project: GNU Octave
            Submitted by: mtmiller
            Submitted on: Thu 28 Jul 2016 02:44:07 PM PDT
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: Any

    _______________________________________________________

Details:

When a user class overrides the subsref method to implement dot indexing, the
wrong value of nargout may be passed in to subsref, incorrectly representing
the number of items to be indexed rather than the number of outputs that the
caller actually wanted.

There may be a Matlab compatible reason for this, judging by the comments in
the code that implements this logic, but I don't understand it and I don't
have access to Matlab to test.

The block of code starting here is what adjusts the value of nargout depending
on what indices were passed in to the object:
http://hg.savannah.gnu.org/hgweb/octave/file/829e0aafebdc/libinterp/octave-value/ov-class.cc#l437

This is largely due to these commits:

http://hg.savannah.gnu.org/hgweb/octave/rev/a76f391a3d02
http://hg.savannah.gnu.org/hgweb/octave/rev/318e0cdd31bd

Can someone decipher whether this adjustment is true and necessary? Can
someone with access to Matlab test what nargout is inside of the subsref
function for various indexing examples?

Here are some tests showing the problem in Octave:


>> type @foo/foo.m

function y = foo()
  y = class(struct(), 'foo');
end

>> type @foo/subsref.m

function varargout = subsref(x, idx)
  nargout
end

>> x = foo;
>> x.asf
ans =  1
>> [a,b,c,d] = x.asdf
ans =  1
error: element number 1 undefined in return list
>> x(0)
ans = 0
>> x(1:10)
ans = 0
>> x{0}
ans =  1
>> x{1:10}
ans =  10






    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?48656>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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