comparison libinterp/parse-tree/pt-eval.cc @ 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 af1a9c1db88e
children cd7bbca7eae3 2a47fa406ed8
comparison
equal deleted inserted replaced
28616:c315a866dbe9 28617:0bac488f17fa
1667 1667
1668 const octave_value *indexed_object = tw.indexed_object (); 1668 const octave_value *indexed_object = tw.indexed_object ();
1669 int index_position = tw.index_position (); 1669 int index_position = tw.index_position ();
1670 int num_indices = tw.num_indices (); 1670 int num_indices = tw.num_indices ();
1671 1671
1672 // Return invalid index value instead of throwing an error so that we 1672 // If indexed_object is nullptr, then this use of 'end' is either
1673 // will see an error about the object that is indexed rather than 1673 // appearing in a function call argument list or in an attempt to
1674 // "end" being used incorrectly. 1674 // index an undefined symbol. There seems to be no reasonable way to
1675 // provide a better error message. So just fail with an invalid use
1676 // message. See bug #58830.
1677
1675 if (! indexed_object) 1678 if (! indexed_object)
1676 return ovl (octave_NaN); 1679 error ("invalid use of 'end': may only be used to index existing value");
1677 1680
1678 if (indexed_object->isobject ()) 1681 if (indexed_object->isobject ())
1679 { 1682 {
1680 octave_value_list args; 1683 octave_value_list args;
1681 1684
1721 1724
1722 return retval; 1725 return retval;
1723 } 1726 }
1724 1727
1725 /* 1728 /*
1726 %!test <*33637> 1729 %!test <*58830>
1727 %! fail ("__undef_sym__ (end)", "'__undef_sym__' undefined"); 1730 %! fail ("__undef_sym__ (end)",
1731 %! "invalid use of 'end': may only be used to index existing value");
1728 */ 1732 */
1729 1733
1730 namespace octave 1734 namespace octave
1731 { 1735 {
1732 octave_value_list 1736 octave_value_list