Mercurial > hg > octave-nkf
diff 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 |
line wrap: on
line diff
--- a/src/pt-assign.cc +++ b/src/pt-assign.cc @@ -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 {