bugGNU Octave - Bugs: bug #45972, Anonymous function handles with...


bug #45972: Anonymous function handles with varargin are not correctly saved.

Submitter:  Olaf Till <i7tiol>
Submitted:  Tue 15 Sep 2015 08:38:12 PM UTC
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Olaf Till Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Wed 15 Aug 2018 05:38:36 PM UTC, comment #5: 

I had to refresh the patch, but I was able to get it to apply to the current development branch.  I also updated the BIST tests to use tempname rather than hard-coded filenames.  See this cset (https://hg.savannah.gnu.org/hgweb/octave/rev/8644e7df7fc7).  It doesn't seem to upset anything according to 'make check' so I am marking this as fixed and closing the report.

Rik <rik5>
Project Administrator
Mon 04 Jul 2016 01:42:08 PM UTC, comment #4: 

This patch still applies.

The test fails if the user has set the default file save format to something other than "text".  The attached patch fixes that.

(file #37704)

Lachlan Andrew <lachlan>
Wed 16 Sep 2015 02:09:49 PM UTC, comment #3: 

Attached such a changeset, containing also a test. Couldn't test the also changed


since it is nowhere used in Octaves code, but I think the change is ok.

(file #34902)

Olaf Till <i7tiol>
Project Member
Wed 16 Sep 2015 01:47:36 PM UTC, comment #2: 

No, varargin is indeed no extra parse tree element, tree_parameter_list has an entry indicating if varargs are taken.

I've seen now that visit_octave_user_function_header calls (indirectly) visit_parameter_list and afterwards prints 'varargin', if necessary.

OTOH, visit_anon_fcn_handle only calls (indirectly) visit_parameter_list and does not care for varargin.

As I see it now, visit_anon_fcn_handle shouldn't be changed (it can't be called from


anyway, since octave_fcn_handle is contained in tree_anon_fcn_handle), but visit_octave_user_function should be changed so that it not cares itself for varargin, but varargin should be cared for by visit_parameter_list.

Olaf Till <i7tiol>
Project Member
Wed 16 Sep 2015 12:14:02 PM UTC, comment #1: 

varargin isn't a parse tree element by itself, is it?  If not, then there shouldn't be a separate visit_varargin method in the tree_walker class.

I'm a bit surprised that visit_parameter_list doesn't handle varargin.  I haven't looked at the code yet, but I think that's probably the place where this should be fixed.

John W. Eaton <jwe>
Project Administrator
Tue 15 Sep 2015 08:38:12 PM UTC, original submission:  

Anonymous function handles using varargin are not correctly saved and thus can't be reloaded. Example:

octave:1> a = @ (varargin) varargin{1}
a =

@() varargin {1}

octave:2> a (1)
ans =  1
octave:3> save ("test.dat", "a")
octave:4> load ("test.dat")
octave:5> a (1)
error: 'varargin' undefined near line 1 column 5
error: called from
     at line -1 column -1
error: evaluating argument list element number 1
error: called from
     at line -1 column -1

It's the same for saving in binary or hdf5 format. The reason is that the function definition is saved with


, which doesn't print the 'varargin' (as you also see above).

I'd like to make a changeset for fixing


, it's not difficult, but there are two possibilities:

1. adding printing of 'varargin' directly in


after printing the parameter list,


2. handling printing of 'varargin' within the printing of the parameter list, i.e. in


I'd vote for 2., but I'll ask at the maintainers list before submitting a changeset.

Olaf Till <i7tiol>
Project Member


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

Attach Files:

Attached Files
file #34902:  bug-45972.cset added by i7tiol (3KiB - 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 rik5 (Posted a comment)
  • -email is unavailable- added by lachlan (Updated the item)
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by i7tiol (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-08-15 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2016-07-04 lachlan Attached File- Added bug_45972_anon_varargin.cset, #37704
    2015-10-08 mtmiller StatusNone Patch Submitted
    2015-09-16 i7tiol Attached File- Added bug-45972.cset, #34902

    Back to the top

    Powered by Savane 3.9