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

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

[Octave-bug-tracker] [bug #63841] nargout is always 0 or 1 for subsref()


From: Fernando
Subject: [Octave-bug-tracker] [bug #63841] nargout is always 0 or 1 for subsref() in classdef methods
Date: Mon, 3 Apr 2023 04:11:54 -0400 (EDT)

Follow-up Comment #17, bug #63841 (project octave):

Yes, the issue from comment #11 broke also with the fix for bug #48693, but
the issue is different from the one described in the original post, and it
seems to be much more complex. Let me explain.

The fix for bug #48693 was introduced to cope with statements like

x{1:10}

where x is a classdef class with custom subsref method. In that case, the
subsref method should be called with nargout set to the number of values that
the indexing argument addresses (10 in this case).

However, the fix did not take into account that in expressions like

a=x{1:10}

or

[a,b]=x{1:10}

nargout should be taken from the number of variables being assigned to (1 or 2
in those cases). That's the cause of the problem described in the original
submission of this bug, and it can be solved with the patch proposed (file
#54549).

A *second problem* is the one identified in comment #11, and I think now that
it should be treated in a separate bug report. It affects sentences like

cm('first').a_property

where cm is a containers.Map object. In this case, cm's subsref method should
be called with nargout=1, but it is called with nargout=5 because 'first' is
an array of 5 elements, so we are in the same case as in

x(1:5).a_property

Contrary to what I said in comment #14, now I think octave is not doing
anything wrong here, because it is valid to assume that nargout will be 5 in
both cases, unless we tell octave otherwise, which we are not telling. In
fact, if you introduce *in Matlab*:


A=tst_nargout;
A('first').a_property


you will see that nargout=5. So in this case we need a way to tell octave that
cm('first').a_property yields only one result. I have seen that in Matlab that
can be done in two different ways:

* with the function numArgumentsFromSubscript (see
https://www.mathworks.com/help/matlab/ref/numargumentsfromsubscript.html)
* with the function listLength (see
https://www.mathworks.com/help/matlab/ref/listlength.html)

The second is the recommended way to do it from version R2021b onwards. That
version also introduces a different way to implement customized indexing,
which is to be preferred over the subsref/subsasgn functions. I don't know
what are the plans for octave in that respect.

So, I propose file #54549 for solving this issue. You can adapt some of the
tests proposed by A.R. Burgers, taking into account that a sentence like

a = cm('first').a_property

should work, but a sentence like

if cm('first').a_property, true, end

does not work for the moment.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63841>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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