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

 
 

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

Submitted by:  None
Submitted on:  Tue 18 Oct 2016 08:09:22 AM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: In ProgressAssigned to: None
Originator Name: Miguel GlasseeOriginator Email: -unavailable-
Open/Closed: OpenRelease: dev
Operating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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.

http://hg.savannah.gnu.org/hgweb/octave/rev/384561642b36
http://hg.savannah.gnu.org/hgweb/octave/rev/976a7a350274

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:

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.

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
commands:

result :

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', []}

Anonymous

 

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

Attach File(s):
   
   
Comment:
   

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
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by mmuetzel (Updated the item)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 9 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 30 Aug 2017 10:12:51 PM UTCjweStatusPatch Submitted=>In Progress
    Wed 05 Apr 2017 06:28:58 PM UTCmmuetzelAttached File-=>Added bug49379_classdef_constructor_inputname.patch, #40270
      StatusConfirmed=>Patch Submitted
    Tue 18 Oct 2016 11:08:16 PM UTCmtmillerCategoryOctave 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)
    Tue 18 Oct 2016 08:09:22 AM UTCNoneAttached File-=>Added ctest.m, #38750

    Back to the top


    Powered by Savane 3.1-cleanup1