Mercurial > octave
changeset 25797:8644e7df7fc7
print and save anonymous functions with varargin correctly (bug #45972)
* pt-pr-code.cc (tree_print_code::visit_parameter_list ()): Print 'varargin' if
marked for varargs.
* pt-pr-code.cc (tree_print_code::visit_octave_user_function_header ()): Never
print 'varargin', rely on visit_parameter_list () for this.
* test/bug-45972/bug-45972.tst: New testfile for saving anonymous functions
with varargin.
* test/module.mk, test/bug-45972/module.mk: Add bug-45972.tst to build system.
author | Olaf Till <olaf.till@uni-jena.de> |
---|---|
date | Wed, 16 Sep 2015 15:13:44 +0200 |
parents | cbb197e84b60 |
children | 4e4ffcca8b5d |
files | libinterp/parse-tree/pt-pr-code.cc test/bug-45972/bug-45972.tst test/bug-45972/module.mk test/module.mk |
diffstat | 4 files changed, 29 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-pr-code.cc Wed Aug 15 09:33:18 2018 -0400 +++ b/libinterp/parse-tree/pt-pr-code.cc Wed Sep 16 15:13:44 2015 +0200 @@ -391,14 +391,6 @@ param_list->accept (*this); - if (takes_varargs) - { - if (len > 0) - m_os << ", "; - - m_os << "varargin"; - } - if (len > 0 || takes_varargs) { m_nesting.pop (); @@ -764,10 +756,13 @@ { elt->accept (*this); - if (p != lst.end ()) + if (p != lst.end () || lst.takes_varargs ()) m_os << ", "; } } + + if (lst.takes_varargs ()) + m_os << "varargin"; } void
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-45972/bug-45972.tst Wed Sep 16 15:13:44 2015 +0200 @@ -0,0 +1,20 @@ +%!test +%! ascii_filename = tempname (); +%! binary_filename = tempname (); +%! hdf5_filename = tempname (); +%! f = @ (x, y, varargin) x + y + varargin{1}; +%! unwind_protect +%! save ("-text", ascii_filename, "f"); +%! save ("-binary", binary_filename, "f"); +%! save ("-hdf5", hdf5_filename, "f"); +%! ascii = load (ascii_filename); +%! binary = load (binary_filename); +%! hdf5 = load (hdf5_filename); +%! assert (f (1, 2, 3), ascii.f (1, 2, 3)); +%! assert (f (1, 2, 3), binary.f (1, 2, 3)); +%! assert (f (1, 2, 3), hdf5.f (1, 2, 3)); +%! unwind_protect_cleanup +%! unlink (ascii_filename); +%! unlink (binary_filename); +%! unlink (hdf5_filename); +%! end_unwind_protect
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/bug-45972/module.mk Wed Sep 16 15:13:44 2015 +0200 @@ -0,0 +1,4 @@ +bug_45972_TEST_FILES = \ + %reldir%/bug-45972.tst + +TEST_FILES += $(bug_45972_TEST_FILES)
--- a/test/module.mk Wed Aug 15 09:33:18 2018 -0400 +++ b/test/module.mk Wed Sep 16 15:13:44 2015 +0200 @@ -57,6 +57,7 @@ include %reldir%/bug-38691/module.mk include %reldir%/bug-41723/module.mk include %reldir%/bug-44940/module.mk +include %reldir%/bug-45972/module.mk include %reldir%/bug-46660/module.mk include %reldir%/bug-49379/module.mk include %reldir%/bug-50014/module.mk