# HG changeset patch # User Kai T. Ohlhus # Date 1593669996 -32400 # Node ID 286fe9352cd6f6b004e8fbb5958d9fba30f950a2 # Parent 627da618dcc4b7e84732c9c132c35ea5738070b3 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. diff -r 627da618dcc4 -r 286fe9352cd6 libinterp/parse-tree/pt-eval.cc --- 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 diff -r 627da618dcc4 -r 286fe9352cd6 scripts/testfun/assert.m --- 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 %! x.b = 1; %! y.a = 1; %! assert (x,y); diff -r 627da618dcc4 -r 286fe9352cd6 test/nest/nest.tst --- 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)