Mercurial > octave
changeset 28617:0bac488f17fa stable
throw error if 'end' is applied to undefined symbol (bug #58830)
* pt-eval.cc (tree_evaluator::Fend): Throw error if indexed_object is
nullptr. Update test.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Aug 2020 23:55:47 -0400 |
parents | c315a866dbe9 |
children | af302efce502 |
files | libinterp/parse-tree/pt-eval.cc |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc Thu Aug 13 23:34:08 2020 -0400 +++ b/libinterp/parse-tree/pt-eval.cc Thu Aug 13 23:55:47 2020 -0400 @@ -1669,11 +1669,14 @@ int index_position = tw.index_position (); int num_indices = tw.num_indices (); - // Return invalid index value instead of throwing an error so that we - // will see an error about the object that is indexed rather than - // "end" being used incorrectly. + // If indexed_object is nullptr, then this use of 'end' is either + // appearing in a function call argument list or in an attempt to + // index an undefined symbol. There seems to be no reasonable way to + // provide a better error message. So just fail with an invalid use + // message. See bug #58830. + if (! indexed_object) - return ovl (octave_NaN); + error ("invalid use of 'end': may only be used to index existing value"); if (indexed_object->isobject ()) { @@ -1723,8 +1726,9 @@ } /* -%!test <*33637> -%! fail ("__undef_sym__ (end)", "'__undef_sym__' undefined"); +%!test <*58830> +%! fail ("__undef_sym__ (end)", +%! "invalid use of 'end': may only be used to index existing value"); */ namespace octave