Mercurial > octave-libtiff
changeset 29376:107091f22e65
Return 0 if first argument to exist() is empty regardless of nargin value (bug #59950).
* variables.cc (Fexist): Return 0 if first argument is empty, regardless of
value of nargin.
* bug-59950.tst: Add tests for empty first argument with a second type argument.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 19 Feb 2021 21:25:07 -0800 |
parents | 8f6a2f5e5934 |
children | be539c9d29d1 |
files | libinterp/corefcn/variables.cc test/bug-59950.tst |
diffstat | 2 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/variables.cc Fri Feb 19 12:39:57 2021 +0900 +++ b/libinterp/corefcn/variables.cc Fri Feb 19 21:25:07 2021 -0800 @@ -472,8 +472,7 @@ // For compatibility with undocumented Matlab behavior, return 0 if // there is an empty built-in object as the only argument. - if (nargin == 1 && args(0).builtin_type () != btyp_unknown - && args(0).isempty ()) + if (args(0).builtin_type () != btyp_unknown && args(0).isempty ()) return ovl (0); // Also for compatibility, return 0 if the second argument is an empty
--- a/test/bug-59950.tst Fri Feb 19 12:39:57 2021 +0900 +++ b/test/bug-59950.tst Fri Feb 19 21:25:07 2021 -0800 @@ -31,7 +31,12 @@ %!assert <59950> (exist ([]), 0) %!assert <59950> (exist ({}), 0) %!assert <59950> (exist (1:0), 0) -%!error exist (containers.Map ()) +%!assert <59950> (exist ('', 'var'), 0) +%!assert <59950> (exist ([], 'builtin'), 0) +%!assert <59950> (exist ({}, 'dir'), 0) +%!assert <59950> (exist (1:0, 'file'), 0) +%!error exist (containers.Map ()) +%!error exist (containers.Map ()) %!assert <59950> (exist ('x', ''), 0) %!assert <59950> (exist ('x', []), 0) %!assert <59950> (exist ('x', {}), 0)