# HG changeset patch # User Markus Mützel # Date 1654518439 -7200 # Node ID 2c8ab613e805ba13f183ce0a1503c76957e641ab # Parent 277e31f0bb602a9a91c0bd6946a75eda2564170c inputParser.m: Adapt for interpreter changes regarding number of output arguments (bug #62420). * scripts/miscellaneous/inputParser.m (validate_arg): Use (nested) try-catch block to correctly handle validation functions with and without output arguments. diff -r 277e31f0bb60 -r 2c8ab613e805 scripts/miscellaneous/inputParser.m --- a/scripts/miscellaneous/inputParser.m Sat Jun 04 16:15:33 2022 +0200 +++ b/scripts/miscellaneous/inputParser.m Mon Jun 06 14:27:19 2022 +0200 @@ -543,9 +543,29 @@ function validate_arg (this, name, val, in) - if (! val (in)) - this.error (sprintf ("failed validation of %s with %s", - toupper (name), func2str (val))); + ## Checking "nargout (val)" doesn't work for builtin functions. + ## So, we need to use this nested try-catch construct. + err = sprintf ('Checked with "%s"', func2str (val)); + try + ok = val (in); + catch exception + if (strcmp (exception.identifier, "Octave:invalid-fun-call")) + ## check if function also fails when called without output argument + try + val (in); + ok = true; + catch exception + ok = false; + err = exception.message; + end_try_catch + else + ok = false; + err = exception.message; + endif + end_try_catch + if (! ok) + this.error (sprintf ("failed validation of %s. %s", + toupper (name), err)); endif this.Results.(name) = in; @@ -859,7 +879,7 @@ %! assert (p.Unmatched, struct ()); ## Test for patch #9241 -%!error +%!error %! p = inputParser (); %! p.addParameter ("a", [], @ischar); %! p.parse ("a", 1);