diff src/ov-class.cc @ 12171:d08901c05c1b

fix bug in class assignment to undefined object with index
author John W. Eaton <jwe@octave.org>
date Wed, 26 Jan 2011 20:39:15 -0500
parents b83162e8f402
children a71c1aa9823e
line wrap: on
line diff
--- a/src/ov-class.cc	Wed Jan 26 17:58:07 2011 -0500
+++ b/src/ov-class.cc	Wed Jan 26 20:39:15 2011 -0500
@@ -504,6 +504,28 @@
                         const std::list<octave_value_list>& idx,
                         const octave_value& rhs)
 {
+  count++;
+  return subsasgn_common (octave_value (this), type, idx, rhs);
+}
+
+octave_value
+octave_class::undef_subsasgn (const std::string& type,
+                              const std::list<octave_value_list>& idx,
+                              const octave_value& rhs)
+{
+  // For compatibility with Matlab, pass [] as the first argument to the
+  // the subsasgn function when the LHS of an indexed assignment is
+  // undefined.
+
+  return subsasgn_common (Matrix (), type, idx, rhs);
+}
+
+octave_value
+octave_class::subsasgn_common (const octave_value& obj,
+                               const std::string& type,
+                               const std::list<octave_value_list>& idx,
+                               const octave_value& rhs)
+{
   octave_value retval;
 
   if (! (in_class_method () || called_from_builtin ()))
@@ -529,8 +551,7 @@
           if (error_state)
             return octave_value_list ();
 
-          count++;
-          args(0) = octave_value (this);
+          args(0) = obj;
 
           // Now comes the magic. Count copies with me:
           // 1. myself (obsolete)