Mercurial > octave
changeset 28525:286fe9352cd6 stable
Interpreter errors on unassigned inputs (bug #58686)
* libinterp/parse-tree/pt-eval.cc (tree_evaluator::convert_to_const_vector):
Throw a proper error instead of silently ignoring the undefined value.
* scripts/testfun/assert.m: Fix comparison of empty structures. Now that the
interpreter is stricter on unassigned inputs to functions.
* test/nest/nest.tst: Mark xtest, because the test never worked. Octave's test
framework got fooled by the interpreter.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Thu, 02 Jul 2020 15:06:36 +0900 |
parents | 627da618dcc4 |
children | 1151ed869686 9e7b2625e574 |
files | libinterp/parse-tree/pt-eval.cc scripts/testfun/assert.m test/nest/nest.tst |
diffstat | 3 files changed, 28 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc Wed Jul 01 16:03:41 2020 +0900 +++ b/libinterp/parse-tree/pt-eval.cc Thu Jul 02 15:06:36 2020 +0900 @@ -1776,7 +1776,9 @@ for (octave_idx_type i = 0; i < tmp_ovl.length (); i++) args.push_back (tmp_ovl(i)); } - else if (tmp.is_defined ()) + else if (! tmp.is_defined ()) + error ("Element %d in argument list is not defined", k + 1); + else args.push_back (tmp); } else
--- a/scripts/testfun/assert.m Wed Jul 01 16:03:41 2020 +0900 +++ b/scripts/testfun/assert.m Thu Jul 02 15:06:36 2020 +0900 @@ -188,27 +188,27 @@ err.observed{end+1} = ["O(" sprintf("%dx", size(cond))(1:end-1) ")"]; err.expected{end+1} = ["E(" sprintf("%dx", size(expected))(1:end-1) ")"]; err.reason{end+1} = "Structure sizes don't match"; + elseif (! strcmp (sort (fieldnames (cond)), + sort (fieldnames (expected)))) + err.index{end+1} = "."; + err.observed{end+1} = "O"; + err.expected{end+1} = "E"; + err.reason{end+1} = "Structure fieldname mismatch"; else try - empty = isempty (cond); - normal = (numel (cond) == 1); - for [v, k] = cond - if (! isfield (expected, k)) - err.index{end+1} = "."; - err.observed{end+1} = "O"; - err.expected{end+1} = "E"; - err.reason{end+1} = ["'" k "'" " is not an expected field"]; - endif - if (empty) - v = {}; - elseif (normal) - v = {v}; - else - v = v(:)'; - endif - ## Recursively call assert for struct array values - assert (v, {expected.(k)}, tol); - endfor + assert (isempty (cond), isempty (expected)); + + if (! isempty (cond)) + for [v, k] = cond + if (numel (cond) == 1) + v = {v}; + else + v = v(:)'; + endif + ## Recursively call assert for struct array values + assert (v, {expected.(k)}, tol); + endfor + endif catch err.index{end+1} = "."; err.observed{end+1} = "O"; @@ -624,7 +624,7 @@ %! x.b = 1; %! y.a = 1; %! assert (x,y); -%!error <'b' is not an expected field> +%!error <Structure fieldname mismatch> %! x.b = 1; %! y.a = 1; %! assert (x,y);
--- a/test/nest/nest.tst Wed Jul 01 16:03:41 2020 +0900 +++ b/test/nest/nest.tst Thu Jul 02 15:06:36 2020 +0900 @@ -37,7 +37,11 @@ %!assert (recursive_nest3 (), 5) -%!assert (script_nest (), 5) +## FIXME: The following test works in Matlab R2020b, but in Octave it never +## worked. The output of "script_nest" is unassigned. This got +## revealed by fixing bug #58686. + +%!xtest assert (script_nest (), 5) %!assert (arg_ret (), 10)