# HG changeset patch # User John W. Eaton # Date 1635601667 14400 # Node ID bfbe6e528af520bb49d23b7661320a4efb9130cc # Parent 03ff3f1020cf56e87a95d56baa582541a8a82960 which: report correct info for classdef constructors (bug #49434) * help.cc (help_system::which): Handle octave_classdef_meta objects. * which.m: Fix test. diff -r 03ff3f1020cf -r bfbe6e528af5 libinterp/corefcn/help.cc --- a/libinterp/corefcn/help.cc Sat Oct 30 09:45:23 2021 -0400 +++ b/libinterp/corefcn/help.cc Sat Oct 30 09:47:47 2021 -0400 @@ -56,6 +56,7 @@ #include "interpreter-private.h" #include "interpreter.h" #include "load-path.h" +#include "ov-classdef.h" #include "ov-fcn-handle.h" #include "ov-usr-fcn.h" #include "ovl.h" @@ -243,21 +244,38 @@ type = ""; - if (name.find_first_of ('.') == std::string::npos) + symbol_table& symtab = m_interpreter.get_symbol_table (); + + octave_value val = symtab.find_function (name); + + if (val.is_defined ()) { - symbol_table& symtab = m_interpreter.get_symbol_table (); - - octave_value val = symtab.find_function (name); + octave_function *fcn = val.function_value (); - if (val.is_defined ()) + if (fcn) { - octave_function *fcn = val.function_value (); + if (fcn->is_classdef_meta ()) + { + octave_classdef_meta *meta_obj + = dynamic_cast (fcn); + + file = meta_obj->file_name (); - if (fcn) + if (meta_obj->is_classdef_constructor ()) + type = "class constructor"; + else if (meta_obj->is_classdef_method ()) + type = "class method"; + else + type = "classdef meta object"; + } + else { + file = fcn->fcn_file_name (); - if (file.empty ()) + if (! file.empty ()) + type = val.is_user_script () ? "script" : "function"; + else { if (fcn->is_user_function ()) type = "command-line function"; @@ -267,8 +285,6 @@ type = "built-in function"; } } - else - type = val.is_user_script () ? "script" : "function"; } } else @@ -280,7 +296,8 @@ file = lp.find_fcn_file (name); } } - else + + if (file.empty ()) { // File query. diff -r 03ff3f1020cf -r bfbe6e528af5 scripts/help/which.m --- a/scripts/help/which.m Sat Oct 30 09:45:23 2021 -0400 +++ b/scripts/help/which.m Sat Oct 30 09:47:47 2021 -0400 @@ -93,9 +93,7 @@ %!test %! str = which ("fftw"); %! assert (str(end-7:end), "fftw.oct"); -%!test -%! str = which ("inputParser"); -%! assert (str, "built-in function"); +%!assert <49434> (which ("inputParser"), file_in_loadpath ("inputParser.m")); %!test %! x = 3; %! str = which ("x");