# HG changeset patch # User John W. Eaton # Date 1597377347 14400 # Node ID 0bac488f17fa3b2e58225e059cd215d509f35931 # Parent c315a866dbe92961f6f2b3c7e107b8e6c6efa32e 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. diff -r c315a866dbe9 -r 0bac488f17fa libinterp/parse-tree/pt-eval.cc --- 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