Mercurial > octave
changeset 31074:2c8ab613e805 stable
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.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Mon, 06 Jun 2022 14:27:19 +0200 |
parents | 277e31f0bb60 |
children | bcadacfac44f 7ea420f2c722 |
files | scripts/miscellaneous/inputParser.m |
diffstat | 1 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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 <failed validation of A with ischar> +%!error <failed validation of A.*ischar> %! p = inputParser (); %! p.addParameter ("a", [], @ischar); %! p.parse ("a", 1);