comparison src/pt-assign.cc @ 14572:000cd393f3c1 stable

avoid error for calls to functions returning varargout that ignore final outputs (bug #36221) * pt-assign.cc (tree_multi_assignment::rvalue): Don't error if more output values are requested than returned when the requested outputs are ignored. New test.
author John W. Eaton <jwe@octave.org>
date Thu, 19 Apr 2012 16:24:14 -0400
parents 72c96de7a403
children
comparison
equal deleted inserted replaced
14571:6131fead3135 14572:000cd393f3c1
429 429
430 k++; 430 k++;
431 } 431 }
432 } 432 }
433 else 433 else
434 error ("element number %d undefined in return list", k+1); 434 {
435 // This can happen for a function like
436 //
437 // function varargout = f ()
438 // varargout{1} = nargout;
439 // endfunction
440 //
441 // called with
442 //
443 // [a, ~] = f ();
444 //
445 // Then the list of of RHS values will contain one
446 // element but we are iterating over the list of all
447 // RHS values. We shouldn't complain that a value we
448 // don't need is missing from the list.
449
450 if (ult.is_black_hole ())
451 {
452 k++;
453 continue;
454 }
455 else
456 error ("element number %d undefined in return list", k+1);
457 }
435 } 458 }
436 459
437 if (error_state) 460 if (error_state)
438 break; 461 break;
439 else if (print_result ()) 462 else if (print_result ())
465 first_execution = false; 488 first_execution = false;
466 489
467 return retval; 490 return retval;
468 } 491 }
469 492
493 /*
494 %!function varargout = f ()
495 %! varargout{1} = nargout;
496 %!endfunction
497 %!
498 %!test
499 %! [a, ~] = f ();
500 %! assert (a, 2);
501 %!test
502 %! [a, ~, ~, ~, ~] = f ();
503 %! assert (a, 5);
504 */
505
470 std::string 506 std::string
471 tree_multi_assignment::oper (void) const 507 tree_multi_assignment::oper (void) const
472 { 508 {
473 return octave_value::assign_op_as_string (op_type ()); 509 return octave_value::assign_op_as_string (op_type ());
474 } 510 }