# HG changeset patch # User Jaroslav Hajek # Date 1295700491 -3600 # Node ID b83162e8f4027a990a83b87e4b1cebf71b2df492 # Parent 85f9a5b211fdc5650ef19d4cc38a1485ad3ee143 fix nested indexed assignemnt in superclasses diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-01-22 Jaroslav Hajek + + * ov-class.cc (octave_class::subsasgn): Find appropriate unique base + before trying any indexed assignment. + 2011-01-22 Konstantinos Poulios * graphics.h.in, graphics.cc (xmtick, ymtick, zmtick): diff --git a/src/ov-class.cc b/src/ov-class.cc --- a/src/ov-class.cc +++ b/src/ov-class.cc @@ -573,6 +573,32 @@ } } + // Find the class in which this method resides before + // attempting to do the indexed assignment. + + std::string method_class = get_current_method_class (); + + octave_base_value *obvp = unique_parent_class (method_class); + if (obvp != this) + { + + if (obvp) + { + obvp->subsasgn (type, idx, rhs); + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); + } + else + error ("malformed class"); + + return retval; + } + // FIXME -- this block of code is the same as the body of // octave_struct::subsasgn. Maybe it could be shared instead of // duplicated. @@ -766,38 +792,39 @@ case '.': { - // Find the class in which this method resides before - // attempting to access the requested field. - - std::string method_class = get_current_method_class (); - - octave_base_value *obvp = unique_parent_class (method_class); + octave_value_list key_idx = idx.front (); - if (obvp) - { - octave_value_list key_idx = idx.front (); + assert (key_idx.length () == 1); - assert (key_idx.length () == 1); - - std::string key = key_idx(0).string_value (); + std::string key = key_idx(0).string_value (); - if (! error_state) - { - obvp->assign (key, t_rhs); + if (t_rhs.is_cs_list ()) + { + Cell tmp_cell = Cell (t_rhs.list_value ()); - if (! error_state) - { - count++; - retval = octave_value (this); - } - else - gripe_failed_assignment (); - } - else - gripe_failed_assignment (); + // The shape of the RHS is irrelevant, we just want + // the number of elements to agree and to preserve the + // shape of the left hand side of the assignment. + + if (numel () == tmp_cell.numel ()) + tmp_cell = tmp_cell.reshape (dims ()); + + map.setfield (key, tmp_cell); } else - error ("malformed class"); + { + Cell tmp_cell(1, 1); + tmp_cell(0) = t_rhs.storable_value (); + map.setfield (key, tmp_cell); + } + + if (! error_state) + { + count++; + retval = octave_value (this); + } + else + gripe_failed_assignment (); } break;