bugGNU Octave - Bugs: bug #49379, classdef constructor: .argn. loses...


bug #49379: classdef constructor: .argn. loses first argument, inputname(n) returns inputname(n+1)

Submitter:  None
Submitted:  Tue 18 Oct 2016 08:09:22 AM UTC
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  In Progress Assigned to:  None
Originator Name:  Miguel Glassee Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Wed 30 Aug 2017 10:12:51 PM UTC, comment #3: 

Markus:  thanks, I pushed your changeset and another one that adds a new test.


Then I realized that the only reason your changeset works and the previous code does not is that argument names are stored in the octave_value_list object and some but not all operations on octave_value_list objects preserve these names.  So when the classdef code inserts the partially constructed object as the first argument of a classdef constructor, it doesn't also shift the argument names, but the method that is used in octave_user_function::call to split the argument list does preserve argument names.  So that's where the inconsistency arises.

Probably it would be better to fix the octave_value_list object to properly preserve the argument names when they are present.  Doing that efficiently might need some changes to the string_vector object as well.

I'm keeping your changeset for now as it fixes the immediate problem, but leaving this report open with a status of "In Progress".

John W. Eaton <jwe>
Project Administrator
Wed 05 Apr 2017 06:28:58 PM UTC, comment #2: 

Attached is a patch that fixes that issue for me.

However, I do not understand the backgrounds of the implementation of classdef in Octave. But this comment in line 473 of ov-usr-fcn.cc looks strange to me:

  // If this function is a classdef constructor, extract the first input
  // argument, which must be the partially constructed object instance.

AFAIU, the constructor is the only "method" of a classdef that does NOT receive the object as the first argument (apart from static methods). So the real problem might be somewhere else and a proper fix should maybe be different from this patch.

(file #40270)

Markus M├╝tzel <mmuetzel>
Project Member
Tue 18 Oct 2016 11:08:16 PM UTC, comment #1: 

Thanks for your bug report. Confirmed here, only affects new-style classdef based classes.

The code for inputname is very simple, the underlying bug is the value of the special variable ".argn." in a classdef constructor function.

>> type classtest
classdef classtest
    function obj = classtest ()
      disp (__varval__ (".argn."));

>> x = y = z = 0;
>> classtest (x, y, z);

  [1,1] = y
  [2,1] = z

Mike Miller <mtmiller>
Project Administrator
Tue 18 Oct 2016 08:09:22 AM UTC, original submission:  

Using inputname(ii) in the class constructor (e.g. the simple class in the attached ctest.m) returns inputname(ii+1).
In other words, when you expect the first input argument, you get the second and so one.  for ii = nargin, you get an 'index out of bounds' error. 

Code : ctest.m attached

a=1; b=2; c = ctest(a,b);

result :

error: ctest: A(I): index out of bounds; value 2 out of bound 1
error: called from
    ctest at line 10 column 34
    inputname at line 38 column 5
    ctest at line 10 column 34

expected: a class c with c.inputnames = {'a', 'b'}

Note: setting the upper bound of the for loop in the constructor to nargin-1 creates a class with c.inputnames = { 'b', []}



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

Attach Files:

Attached Files
file #38750:  ctest.m added by None (257B - application/octet-stream)


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 mmuetzel (Updated the item)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (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 project members can vote.





    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-30 jwe StatusPatch Submitted In Progress
    2017-04-05 mmuetzel Attached File- Added bug49379_classdef_constructor_inputname.patch, #40270
        StatusConfirmed Patch Submitted
    2016-10-18 mtmiller CategoryOctave Function Interpreter
        StatusNone Confirmed
        Release4.0.0 dev
        Operating SystemMicrosoft Windows Any
        Summaryinputname(ii) in class constructor returns inputname(ii+1) classdef constructor: .argn. loses first argument, inputname(n) returns inputname(n+1)
    2016-10-18 None Attached File- Added ctest.m, #38750

    Back to the top

    Powered by Savane 3.9