# HG changeset patch # User Jaroslav Hajek # Date 1281337440 -7200 # Node ID 333bf09e3b6e6d4834c0a7e11564f1d7e2a1ece2 # Parent 307c8396bc8338d104df4051023660d51d19cf69 only allow struct assignments to non-struct values for empty arrays diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2010-08-09 Jaroslav Hajek + + * ov.cc (octave_value::assign (assign_op, const std::string&, + const std::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 * DLD-FUNCTIONS/config-module.awk: Add newlines to divide blocks diff --git a/src/ov-cell.cc b/src/ov-cell.cc --- 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; diff --git a/src/ov.cc b/src/ov.cc --- 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;