Go patch committed: Don't deref named pointer type for method

Ian Lance Taylor iant@golang.org
Mon Nov 24 17:20:00 GMT 2014


This patch by Chris Manghane fixes the Go compiler to not dereference
a named pointer type when looking up a method.  Before this patch that
could happen if the pointer type pointed to a struct with an inherited
method.  This is http://golang.org/issue/9018.  Bootstrapped and ran
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
-------------- next part --------------
diff -r 547a3bf5788a go/types.cc
--- a/go/types.cc	Fri Nov 21 10:21:33 2014 -0800
+++ b/go/types.cc	Mon Nov 24 09:05:18 2014 -0800
@@ -10035,6 +10035,18 @@
 
   if (found_level == 0)
     return false;
+  else if (found_is_method
+	   && type->named_type() != NULL
+	   && type->points_to() != NULL)
+    {
+      // If this is a method inherited from a struct field in a named pointer
+      // type, it is invalid to automatically dereference the pointer to the
+      // struct to find this method.
+      if (level != NULL)
+	*level = found_level;
+      *is_method = true;
+      return false;
+    }
   else if (!found_ambig1.empty())
     {
       go_assert(!found_ambig1.empty());


More information about the Gcc-patches mailing list