# HG changeset patch # User Rik # Date 1307229038 25200 # Node ID 4972eb61c6d66dfca8a4ad5f91b96cafd8c8f07b # Parent da6cbb75236832c72b28be98898f2120952cc454 Fix bug with error() not accepting an empty struct input (Bug #33428). * nargchk.m, nargoutchk.m: Return scalar empty struct if there is no error. * error.cc: Accept empty struct as input with no error, per Matlab. diff -r da6cbb752368 -r 4972eb61c6d6 scripts/general/nargchk.m --- a/scripts/general/nargchk.m Sat Jun 04 16:05:37 2011 -0700 +++ b/scripts/general/nargchk.m Sat Jun 04 16:10:38 2011 -0700 @@ -56,11 +56,12 @@ if (strcmpi (outtype, "string")) msg = msg.message; elseif (isempty (msg.message)) - msg = struct ([]); + msg = struct (); endif endfunction + ## Tests %!shared stmin, stmax %! stmin = struct ("message", "not enough input arguments", @@ -73,7 +74,7 @@ %!assert (nargchk (0, 1, 2), "too many input arguments") %!assert (nargchk (0, 1, 2, "string"), "too many input arguments") ## Struct outputs -%!assert (nargchk (0, 1, 0, "struct"), struct([])) -%!assert (nargchk (0, 1, 1, "struct"), struct([])) +%!assert (nargchk (0, 1, 0, "struct"), struct()) +%!assert (nargchk (0, 1, 1, "struct"), struct()) %!assert (nargchk (1, 1, 0, "struct"), stmin) %!assert (nargchk (0, 1, 2, "struct"), stmax) diff -r da6cbb752368 -r 4972eb61c6d6 scripts/general/nargoutchk.m --- a/scripts/general/nargoutchk.m Sat Jun 04 16:05:37 2011 -0700 +++ b/scripts/general/nargoutchk.m Sat Jun 04 16:10:38 2011 -0700 @@ -55,17 +55,13 @@ if (strcmpi (outtype, "string")) msg = msg.message; - else - if (isempty (msg.message)) - msg = struct ([]); - endif - ## FIXME: remove the error below if error is modified to accept - ## struct inputs - error ("nargoutchk: error does not yet support struct inputs"); + elseif (isempty (msg.message)) + msg = struct (); endif endfunction + ## Tests %!shared stmin, stmax %! stmin = struct ("message", "not enough output arguments", @@ -78,7 +74,7 @@ %!assert (nargoutchk (0, 1, 2), "too many output arguments") %!assert (nargoutchk (0, 1, 2, "string"), "too many output arguments") ## Struct outputs -#%!assert (nargoutchk (0, 1, 0, "struct"), struct([])) -#%!assert (nargoutchk (0, 1, 1, "struct"), struct([])) +#%!assert (nargoutchk (0, 1, 0, "struct"), struct()) +#%!assert (nargoutchk (0, 1, 1, "struct"), struct()) #%!assert (nargoutchk (1, 1, 0, "struct"), stmin) #%!assert (nargoutchk (0, 1, 2, "struct"), stmax) diff -r da6cbb752368 -r 4972eb61c6d6 src/error.cc --- a/src/error.cc Sat Jun 04 16:05:37 2011 -0700 +++ b/src/error.cc Sat Jun 04 16:10:38 2011 -0700 @@ -1066,6 +1066,10 @@ octave_scalar_map m = args(0).scalar_map_value (); + // empty struct is not an error. return and resume calling function. + if (m.nfields () == 0) + return retval; + if (m.contains ("message")) { octave_value c = m.getfield ("message");