Mercurial > hg > octave-nkf
diff src/ov-class.cc @ 12127:b83162e8f402
fix nested indexed assignemnt in superclasses
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 22 Jan 2011 13:48:11 +0100 |
parents | 12df7854fa7c |
children | d08901c05c1b |
line wrap: on
line diff
--- 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;