diff mbox

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

Message ID CAOyqgcXi4FgLEW9miBLgK3F-KyaSOCiumNL2MA8y3QLCtoPoMg@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor Nov. 24, 2014, 5:10 p.m. UTC
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
diff mbox

Patch

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());