comparison libinterp/parse-tree/pt-assign.cc @ 20283:011a364b4d78

improve compatibility of indexed assignment (bug #43813) * oct-lvalue.h, oct-lvalue.cc (octave_lvalue::index_type, octave_lvalue::index_is_empty): New functions. * pt-assign.cc (tree_multi_assignment::rvalue): For expressions like [lhs{:}] = fcn (args) with LHS undefined, and in which FCN produces an output given nargout equal to zero, convert LHS to a one-element cell array indexed by 1.
author John W. Eaton <jwe@octave.org>
date Fri, 05 Jun 2015 15:51:04 -0400
parents 4197fc428c7d
children dd6345fd8a97
comparison
equal deleted inserted replaced
20282:78293a28f2a5 20283:011a364b4d78
258 258
259 octave_idx_type nel = ult.numel (); 259 octave_idx_type nel = ult.numel ();
260 260
261 if (nel != 1) 261 if (nel != 1)
262 { 262 {
263 // Huge kluge so that wrapper scripts with lines like
264 //
265 // [varargout{1:nargout}] = fcn (args);
266 //
267 // Will work the same as calling fcn directly when nargout
268 // is 0 and fcn produces more than one output even when
269 // nargout is 0. This only works if varargout has not yet
270 // been defined. See also bug #43813.
271
272 if (lvalue_list.size () == 1 && nel == 0 && n > 0
273 && ! ult.is_black_hole () && ult.is_undefined ()
274 && ult.index_type () == "{" && ult.index_is_empty ())
275 {
276 // Convert undefined lvalue with empty index to a cell
277 // array with a single value and indexed by 1 to
278 // handle a single output.
279
280 nel = 1;
281
282 ult.define (Cell (1, 1));
283
284 ult.clear_index ();
285 std::list<octave_value_list> idx;
286 idx.push_back (octave_value_list (octave_value (1)));
287 ult.set_index ("{", idx);
288 }
289
263 if (k + nel <= n) 290 if (k + nel <= n)
264 { 291 {
265 // This won't do a copy. 292 // This won't do a copy.
266 octave_value_list ovl = rhs_val.slice (k, nel); 293 octave_value_list ovl = rhs_val.slice (k, nel);
267 294