# HG changeset patch # User John W. Eaton # Date 1334867054 14400 # Node ID 000cd393f3c1391f57569bb79746cd5c2314807f # Parent 6131fead3135a9d6d74fe8a035c25c77fd785fcd 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. diff -r 6131fead3135 -r 000cd393f3c1 src/pt-assign.cc --- a/src/pt-assign.cc Wed Apr 18 14:21:34 2012 -0400 +++ b/src/pt-assign.cc Thu Apr 19 16:24:14 2012 -0400 @@ -431,7 +431,30 @@ } } else - error ("element number %d undefined in return list", k+1); + { + // This can happen for a function like + // + // function varargout = f () + // varargout{1} = nargout; + // endfunction + // + // called with + // + // [a, ~] = f (); + // + // Then the list of of RHS values will contain one + // element but we are iterating over the list of all + // RHS values. We shouldn't complain that a value we + // don't need is missing from the list. + + if (ult.is_black_hole ()) + { + k++; + continue; + } + else + error ("element number %d undefined in return list", k+1); + } } if (error_state) @@ -467,6 +490,19 @@ return retval; } +/* +%!function varargout = f () +%! varargout{1} = nargout; +%!endfunction +%! +%!test +%! [a, ~] = f (); +%! assert (a, 2); +%!test +%! [a, ~, ~, ~, ~] = f (); +%! assert (a, 5); +*/ + std::string tree_multi_assignment::oper (void) const {