changeset 14343:acc26b860afa stable

fix indexed assignment bug (bug #35482) * pt-idx.cc (make_value_list): New argument, rvalue. Only require object to be defined if rvalue is true. (tree_index_expression::lvalue): Call make_value_list with rvalue argument set to false. New test.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Feb 2012 15:42:28 -0500
parents 2cd56a5e3a66
children 06f706e92771
files src/pt-idx.cc
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/pt-idx.cc	Tue Feb 07 11:41:33 2012 -0500
+++ b/src/pt-idx.cc	Wed Feb 08 15:42:28 2012 -0500
@@ -177,13 +177,13 @@
 
 static inline octave_value_list
 make_value_list (tree_argument_list *args, const string_vector& arg_nm,
-                 const octave_value *object)
+                 const octave_value *object, bool rvalue = true)
 {
   octave_value_list retval;
 
   if (args)
     {
-      if (object && args->has_magic_end () && object->is_undefined ())
+      if (rvalue && object && args->has_magic_end () && object->is_undefined ())
         gripe_invalid_inquiry_subscript ();
       else
         retval = args->convert_to_const_vector (object);
@@ -476,7 +476,7 @@
             case '(':
               {
                 octave_value_list tidx
-                  = make_value_list (*p_args, *p_arg_nm, &tmp);
+                  = make_value_list (*p_args, *p_arg_nm, &tmp, false);
 
                 idx.push_back (tidx);
 
@@ -496,7 +496,7 @@
             case '{':
               {
                 octave_value_list tidx
-                  = make_value_list (*p_args, *p_arg_nm, &tmp);
+                  = make_value_list (*p_args, *p_arg_nm, &tmp, false);
 
                 if (tmp.is_undefined ())
                   {
@@ -601,6 +601,18 @@
 
 /*
 %!test
+%! clear x
+%! clear y
+%! y = 3;
+%! x(y(end)) = 1;
+%! assert (x, [0, 0, 1]);
+%! clear x
+%! clear y
+%! y = {3};
+%! x(y{end}) = 1;
+%! assert (x, [0, 0, 1]);
+
+%!test
 %! x = {1, 2, 3};
 %! [x{:}] = deal (4, 5, 6);
 %! assert (x, {4, 5, 6});