changeset 28696:2a47fa406ed8 stable

allow 'end' indexing to work for nested function calls (bug #58953) * pt-eval.cc (tree_evaluator::convert_to_const_vector): Don't bother checking whether the arg list has magic end token. Always stash object info for expressions that don't look like function calls. New test.
author John W. Eaton <jwe@octave.org>
date Tue, 08 Sep 2020 22:41:19 -0400
parents a927fe30358d
children 8d04d7c58d49 d45d1b4bb919
files libinterp/parse-tree/pt-eval.cc
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Fri Sep 04 11:29:59 2020 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Tue Sep 08 22:41:19 2020 -0400
@@ -1729,6 +1729,12 @@
 %!test <*58830>
 %! fail ("__undef_sym__ (end)",
 %!       "invalid use of 'end': may only be used to index existing value");
+
+%!test <58953>
+%! x = 1:10;
+%! assert (x(end), 10);
+%! assert (x(minus (end, 1)), 9);
+%! assert (x(minus (minus (end, 1), 1)), 8);
 */
 
 namespace octave
@@ -1742,10 +1748,8 @@
     // need a different way of asking an octave_value object this
     // question?
 
-    bool stash_object = (arg_list->includes_magic_end ()
-                         && object
-                         && ! (object->is_function ()
-                               || object->is_function_handle ()));
+    bool stash_object = (object && ! (object->is_function ()
+                                      || object->is_function_handle ()));
 
     unwind_protect_var<const octave_value *> upv1 (m_indexed_object);
     unwind_protect_var<int> upv2 (m_index_position);