diff src/symtab.cc @ 13147:6c952376482d

look for methods before constructors * symtab.cc (symbol_table::fcn_info::fcn_info_rep::find): Look for class methods before constructors, contrary to Matlab documentation. * test/ctor-vs-method: New directory of test classes. * test/test_ctor_vs_method.m: New file. * test/Makefile.am: Include ctor-vs-method/module.mk. (FCN_FILES): Include test_ctor_vs_method.m in the list.
author John W. Eaton <jwe@octave.org>
date Fri, 16 Sep 2011 15:42:06 -0400
parents e81ddf9cacd5
children 0ec8413d4bbc
line wrap: on
line diff
--- a/src/symtab.cc	Fri Sep 16 21:04:30 2011 +0200
+++ b/src/symtab.cc	Fri Sep 16 15:42:06 2011 -0400
@@ -575,13 +575,16 @@
 //   variable
 //   subfunction
 //   private function
+//   class method
 //   class constructor
-//   class method
 //   legacy dispatch
 //   command-line function
 //   autoload function
 //   function on the path
 //   built-in function
+//
+// Matlab documentation states that constructors have higher precedence
+// than methods, but that does not seem to be the case.
 
 octave_value
 symbol_table::fcn_info::fcn_info_rep::find (const octave_value_list& args,
@@ -687,6 +690,18 @@
         }
     }
 
+  // Class methods.
+
+  if (! args.empty ())
+    {
+      std::string dispatch_type = get_dispatch_type (args);
+
+      octave_value fcn = find_method (dispatch_type);
+
+      if (fcn.is_defined ())
+        return fcn;
+    }
+
   // Class constructors.  The class name and function name are the same.
 
   str_val_iterator q = class_constructors.find (name);
@@ -716,18 +731,6 @@
         }
     }
 
-  // Class methods.
-
-  if (! args.empty ())
-    {
-      std::string dispatch_type = get_dispatch_type (args);
-
-      octave_value fcn = find_method (dispatch_type);
-
-      if (fcn.is_defined ())
-        return fcn;
-    }
-
   // Legacy dispatch.
 
   if (! args.empty () && ! dispatch_map.empty ())