Mercurial > octave
changeset 28174:47d4a84a5725
fieldnames.m: Fix handling of old-style @class objects (bug #58012).
* fieldnames.m: Add try/catch block to first use classdef access sequence and
then fall back to @class access sequence. Add BIST test for @class objects.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 26 Mar 2020 15:06:09 -0700 |
parents | e3ef089c5529 |
children | 4ca254b41ea8 |
files | scripts/miscellaneous/fieldnames.m |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/miscellaneous/fieldnames.m Wed Mar 25 18:29:20 2020 +0100 +++ b/scripts/miscellaneous/fieldnames.m Thu Mar 26 15:06:09 2020 -0700 @@ -52,7 +52,11 @@ if (isstruct (obj)) names = __fieldnames__ (obj); elseif (isobject (obj)) - names = properties (obj); + try + names = properties (obj); ## classdef object + catch + names = __fieldnames__ (obj); ## @class object + end_try_catch elseif (isjava (obj) || ischar (obj)) ## FIXME: Function prototype that accepts java obj exists, but doesn't ## work if obj is java.lang.String. Convert obj to classname. @@ -87,6 +91,12 @@ %! f = fieldnames (m); %! assert (f, {"Count"; "KeyType"; "ValueType"; "map"; "numeric_keys"}); +## Test old-style @class object +%!test +%! obj = ftp (); +%! f = fieldnames (obj); +%! assert (f, {"host"; "username"; "password"; "curlhandle"}); + ## Test Java classname by passing classname %!testif HAVE_JAVA; usejava ("jvm") %! names = fieldnames ("java.lang.Double");