Mercurial > hg > octave-nkf
diff src/ov.cc @ 10544:9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 23 Apr 2010 11:23:43 +0200 |
parents | 4d1fc073fbb7 |
children | d1194069e58c |
line wrap: on
line diff
--- a/src/ov.cc +++ b/src/ov.cc @@ -1271,7 +1271,7 @@ return rep->subsasgn (type, idx, rhs); } -octave_value +octave_value& octave_value::assign (assign_op op, const std::string& type, const std::list<octave_value_list>& idx, const octave_value& rhs) @@ -1284,15 +1284,20 @@ if (op != op_asn_eq) { - octave_value t = subsref (type, idx); - - if (! error_state) + if (is_defined ()) { - binary_op binop = op_eq_to_binary_op (op); + octave_value t = subsref (type, idx); if (! error_state) - t_rhs = do_binary_op (binop, t, rhs); + { + binary_op binop = op_eq_to_binary_op (op); + + if (! error_state) + t_rhs = do_binary_op (binop, t, rhs); + } } + else + error ("in computed assignment A(index) OP= X, A must be defined first"); } if (! error_state) @@ -1300,26 +1305,26 @@ if (type[0] == '.' && ! (is_map () || is_object ())) { octave_value tmp = Octave_map (); - retval = tmp.subsasgn (type, idx, t_rhs); + *this = tmp.subsasgn (type, idx, t_rhs); } else - retval = subsasgn (type, idx, t_rhs); + *this = 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 ()); } - return retval; + return *this; } -const octave_value& +octave_value& octave_value::assign (assign_op op, const octave_value& rhs) { if (op == op_asn_eq) // Regularize a null matrix if stored into a variable. operator = (rhs.storable_value ()); - else + else if (is_defined ()) { octave_value_typeinfo::assign_op_fcn f = 0; @@ -1358,6 +1363,8 @@ } } } + else + error ("in computed assignment A OP= X, A must be defined first"); return *this; }