changeset 23365:7b594fcfa32b

improve inputParser compatibility for optional args (bug #50752) * inputParser.m (parse): Recognize parameter/value pairs when procssing optional arguments.
author John W. Eaton <jwe@octave.org>
date Fri, 07 Apr 2017 12:22:54 -0400
parents 695ff87bc838
children 56c59b3f9172
files scripts/general/inputParser.m
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/inputParser.m	Fri Apr 07 11:01:17 2017 -0400
+++ b/scripts/general/inputParser.m	Fri Apr 07 12:22:54 2017 -0400
@@ -402,6 +402,13 @@
       while (vidx < pnargin && idx < nOpt)
         opt = this.Optional{++idx};
         in  = varargin{++vidx};
+        if (this.is_argname ("Parameter", in) && vidx < pnargin)
+          ## This looks like an optional parameter/value pair, not an
+          ## optional positional parameter.
+          idx -= 1;
+          vidx -= 1;
+          break
+        endif
         try
           valid_option = opt.val (in);
         catch
@@ -728,7 +735,7 @@
 %! assert (p.Results, struct ("foo", "qux"))
 
 ## FIXME: This somehow works in Matlab
-%!xtest
+%!test <50752>
 %! p = inputParser;
 %! p.addOptional ("op1", "val");
 %! p.addParameter ("line", "tree");