bugGNU Octave - Bugs: bug #62639, inputParser fails to add Optional...


bug #62639: inputParser fails to add Optional argument with empty cell default value

Submitter:  None
Submitted:  Thu 16 Jun 2022 11:45:16 AM UTC
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Ready For Test Assigned to:  None
Originator Name:  Nikita Beliy Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 7.1.90
Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Tue 21 Jun 2022 01:45:56 PM UTC, comment #5: 

I pushed a fix to the stable branch here:

I forgot to include some BISTs in that changeset. So, I followed up with some tests for this here:

Marking as ready for test.

Markus Mützel <mmuetzel>
Project Member
Tue 21 Jun 2022 01:23:19 PM UTC, comment #4: 

Not a regression. But might still be worth fixing on stable.

Markus Mützel <mmuetzel>
Project Member
Tue 21 Jun 2022 01:18:31 PM UTC, comment #3: 

IIUC, this is an issue whenever the default value for an optional parameter is a cell. (Not only for empty cells.)

An alternative (maybe less invasive) fix might be:

diff -r 05729b0e39e4 scripts/miscellaneous/inputParser.m
--- a/scripts/miscellaneous/inputParser.m        Mon Jun 20 17:27:39 2022 -0400
+++ b/scripts/miscellaneous/inputParser.m        Tue Jun 21 15:17:05 2022 +0200
@@ -275,6 +275,9 @@
                 "after Parameter or Switch"]);
       this.validate_name ("Optional", name);
+      if (iscell (def))
+        def = {def};
+      endif
       this.Optional{end+1} = struct ("name", name, "def", def, "val", val);

Markus Mützel <mmuetzel>
Project Member
Tue 21 Jun 2022 12:04:00 PM UTC, comment #2: 

OP here.

An easy solution will be to use instead of cellarray of structures, the structarray:

In inputParser.m:276

Optional = struct("name", {}, "def", {}, "val", {});

Filling (line 328):

this.Optional{end+1}.name = name;
this.Optional{end}.def = def;
this.Optional{end}.val = val;

Accessing (line 401):
opt = this.Optional(++idx);
Essentually replacing {} by ().

Thu 16 Jun 2022 03:48:47 PM UTC, comment #1: 

Confirmed.  This is still an issue with the current development version so changing release to "dev".

John W. Eaton <jwe>
Project Administrator
Thu 16 Jun 2022 11:45:16 AM UTC, original submission:  

When creating argument parser with an empty optional argument:


> p = inputParser;
> p.addOptional('opt',{});
> p.parse('opt', 'xxx')

fails with error:

 error: value on right hand side of assignment is undefined
 error: called from
   parse at line 441 column 35

In Matlab (R2017b) works as expected:


>> p = inputParser;
>> p.addOptional('opt',{});
>> p.parse('opt', 'xxx');
>> p.Results
ans =

  struct with fields:

    opt: 'xxx'

The problem comes from inputParser.m:324:

this.Optional{end+1} = struct ("name", name, "def", def, "val", val);

The creation of structure with an empty cell as value creates an empty structure (both in matlab and octave):


> sp = struc(p);
> sp.Optional
ans =
  [1,1] =

    0x0 struct array containing the fields:




>> sp = struct(p);
>> sp.Optional

ans =

  struct with fields:

         name: 'opt'
      default: {}
    validator: []

P.S. Can't test later versions of octave, the 5.2.0-1 is the latest one for Ubuntu 20.04



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

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by nrjank (Updated the item)
  • -email is unavailable- added by jwe (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-06-21 mmuetzel StatusConfirmed Ready For Test
    2022-06-21 mmuetzel Releasedev 7.1.90
        Operating SystemGNU/Linux Any
    2022-06-16 nrjank SummaryimputParser fails to add Optional argument with empty cell default value inputParser fails to add Optional argument with empty cell default value
    2022-06-16 jwe Item GroupMatlab Compatibility Unexpected Error or Warning
        StatusNone Confirmed
        Release5.2.0 dev

    Back to the top

    Powered by Savane 3.9