diff mbox

Go patch committed: Fix method sets with embedded pointer types

Message ID mcrehbnjmyp.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor June 27, 2013, 8:52 p.m. UTC
This patch from Rémy Oudompheng fixes the handling of method sets for
structs with embedded pointer fields.  Any such methods can be value
methods of the struct, not just pointer methods.  Bootstrapped and ran
Go testsuite on x86_64-unknown-linux-gnu.  Committed to mainline and 4.8
branch.

Ian
diff mbox

Patch

diff -r bd3d5e75023b go/types.cc
--- a/go/types.cc	Thu Jun 27 12:19:13 2013 -0700
+++ b/go/types.cc	Thu Jun 27 13:49:08 2013 -0700
@@ -9396,13 +9396,18 @@ 
 	fnt = pf->type()->deref()->named_type();
       go_assert(fnt != NULL);
 
+      // Methods with pointer receivers on embedded field are
+      // inherited by the pointer to struct, and also by the struct
+      // type if the field itself is a pointer.
+      bool can_be_pointer = (receiver_can_be_pointer
+			     || pf->type()->points_to() != NULL);
       int sublevel = level == NULL ? 1 : *level + 1;
       bool sub_is_method;
       std::string subambig1;
       std::string subambig2;
       bool subfound = Type::find_field_or_method(fnt,
 						 name,
-						 receiver_can_be_pointer,
+						 can_be_pointer,
 						 seen,
 						 &sublevel,
 						 &sub_is_method,