Mercurial > hg > octave-max
changeset 10871:333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 09 Aug 2010 09:04:00 +0200 |
parents | 307c8396bc83 |
children | 988d16d5ae34 |
files | src/ChangeLog src/ov-cell.cc src/ov.cc |
diffstat | 3 files changed, 39 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2010-08-09 Jaroslav Hajek <highegg@gmail.com> + + * ov.cc (octave_value::assign (assign_op, const std::string&, + const std::list<octave_value_list>&, const octave_value&): + Don't attempt to fix struct assignment to non-struct values here. + Check for successful assignment before overwriting this. + + * ov-cell.cc (octave_cell::subsasgn): Allow dot assignment into empty + cell. + 2010-08-08 Rik <octave@nomad.inbox5.com> * DLD-FUNCTIONS/config-module.awk: Add newlines to divide blocks
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -263,7 +263,7 @@ // Allow conversion of empty cell array to some other // type in cases like // - // x = []; x(i).f = rhs + // x = {}; x(i).f = rhs octave_value tmp = octave_value::empty_conv (type, rhs); @@ -328,8 +328,15 @@ case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + if (is_empty ()) + { + // Do nothing; the next branch will handle it. + } + else + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } } break; @@ -402,8 +409,22 @@ case '.': { - std::string nm = type_name (); - error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + if (is_empty ()) + { + // Allow conversion of empty cell array to some other + // type in cases like + // + // x = {}; x.f = rhs + + octave_value tmp = octave_value::empty_conv (type, rhs); + + return tmp.subsasgn (type, idx, rhs); + } + else + { + std::string nm = type_name (); + error ("%s cannot be indexed with %c", nm.c_str (), type[0]); + } } break;
--- a/src/ov.cc +++ b/src/ov.cc @@ -1332,17 +1332,13 @@ if (! error_state) { - if (type[0] == '.' && ! (is_map () || is_object ())) - { - octave_value tmp = Octave_map (); - *this = tmp.subsasgn (type, idx, t_rhs); - } - else - *this = subsasgn (type, idx, t_rhs); + octave_value tmp = subsasgn (type, idx, t_rhs); if (error_state) gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), type_name (), rhs.type_name ()); + else + *this = tmp; } return *this;