bugGNU Octave - Bugs: bug #34478, argn is undefined inside subsref

 
 

bug #34478: argn is undefined inside subsref

Submitter:  Carnë Draug <carandraug>
Submitted:  Tue 04 Oct 2011 06:49:30 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.4.2 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 30 Jul 2016 08:24:57 PM UTC, comment #7: 

I don't even remember why I needed argn within subsref (considering the timing I was probably trying to workaround lack of classdef to implement inputParser for the general package).

I no longer have a use case for this and seems like no one else has ever had an issue with it either.  Your reasoning about subsref not really be called by the user makes sense too. So yeah, closed as won't fix.

I see that you already opened the unrelated bug about nargout as bug #48656

Carnë Draug <carandraug>
Group Member
Thu 28 Jul 2016 09:16:03 PM UTC, comment #6: 

I think the reason that argn is not defined is because when you use the indexing operators, subsref is called internally on your behalf, you are not calling it directly. The argument strings that are normally passed in argn must be stored by the parser when a function is called, and are not available in this case.

With carandraug's original example code:


>> a = testClass;
>> a.method
error: 'argn' undefined near line 2 column 3
error: called from
    subsref at line 2 column 3


>> subsref (a, ".", "method")
argn =

a
"."
"method"

ans = <class testClass>


To work around this the octave_class methods that dispatch to the m-file functions would have to somehow forward the literal argument strings on to the m-file function. I don't know that this is worth trying to solve or even desirable.

This same lack of argument strings would apply to any other class methods that are not called directly by the user.

Close as won't fix?

Mike Miller <mtmiller>
Group Member
Thu 28 Jul 2016 09:01:48 PM UTC, comment #5: 

Sorry for the noise, I am unsure about the original argn problem, but I think nargout being wrong is a completely different bug.

Mike Miller <mtmiller>
Group Member
Thu 28 Jul 2016 06:48:52 PM UTC, comment #4: 

Just hit this error and found this open bug report. This is due to this chunk of code: http://hg.savannah.gnu.org/hgweb/octave/file/829e0aafebdc/libinterp/octave-value/ov-class.cc#l437

Does anyone know what Matlab compatibility this is attempting to deal with? Blame points me to these two changes

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

So it's the way that the @foo/subsref.m function is called by octave_class that is to blame, but I don't understand what this is meant to be doing to attempt to fix it.

It looks like it's setting up a heuristic for what kinds of indexing could lead to more return values than the caller actually requested, maybe? Is this even needed now?

Mike Miller <mtmiller>
Group Member
Tue 14 Jan 2014 01:13:59 AM UTC, comment #3: 

attached source code of example

(file #30267)

Felipe G. Nievinski <fgnievinski>
Tue 14 Jan 2014 01:06:55 AM UTC, comment #2: 

likely related: nargout silently fails.

with @aclass/subsref.m as follows:


function varargout = subsref (in, idx)
  fprintf ('NARGOUT: %d\n', nargout ());
endfunction


I find, correctly:


>> [a,b] = aclass()(1);
NARGOUT: 2


and:


>> [a,b] = subsref(aclass(), []);
NARGOUT: 2


but, incorrectly:


>> [a,b] = aclass(){1};
NARGOUT: 1


and also:


>> [a,b] = aclass().field;
NARGOUT: 1


Felipe G. Nievinski <fgnievinski>
Thu 06 Oct 2011 10:57:52 AM UTC, comment #1: 

Hi

just for the record, replacing argn with

b = _varval_ (".argn.");

on subsref.m still causes an error about not being defined. Here's the exact error:


error: value on right hand side of assignment is undefined
error: called from:
error:   /home/carandraug/development/inputParser/@testClass/subsref.m at line 2, column 5


Carnë Draug <carandraug>
Group Member
Tue 04 Oct 2011 06:49:30 PM UTC, original submission:  

Hi

I was trying to implement a new class and found that when calling argn inside subsref, it is not defined (note that this also causes inputname to fail inside subsref).

I uploaded a file with the most minimal case to replicate this behaviour. There's only the class constructor and the subsref function which only checks argn.

The following code will fail now with:

> a = testClass;
> a.method

error: `argn' undefined near line 2 column 3
error: called from:
error:   /home/carandraug/development/inputParser/@testClass/subsref.m at line 2, column 3

And I'm using octave 3.4.2 in Debian Squeeze (not the one in the repos, compiled by me).

Carnë Draug <carandraug>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #30267:  @aclass.zip added by fgnievinski (478B - application/x-zip-compressed)
file #24098:  @testClass.tar added by carandraug (10KiB - application/x-tar)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by fgnievinski (Posted a comment)
  • -email is unavailable- added by carandraug (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-07-30 carandraug Open/ClosedOpen Closed
    2016-07-28 mtmiller StatusNone Wont Fix
    2014-01-14 fgnievinski Attached File- Added @aclass.zip, #30267
    2011-10-04 carandraug Attached File- Added @testClass.tar, #24098

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code