changeset 30260:bfbe6e528af5

which: report correct info for classdef constructors (bug #49434) * help.cc (help_system::which): Handle octave_classdef_meta objects. * which.m: Fix test.
author John W. Eaton <jwe@octave.org>
date Sat, 30 Oct 2021 09:47:47 -0400
parents 03ff3f1020cf
children a49c635b179d
files libinterp/corefcn/help.cc scripts/help/which.m
diffstat 2 files changed, 29 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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<octave_classdef_meta *> (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.
 
--- 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");