Patchwork Go patch committed: Fix method sets with embedded pointer types

login
register
mail settings
Submitter Ian Taylor
Date June 27, 2013, 8:52 p.m.
Message ID <mcrehbnjmyp.fsf@iant-glaptop.roam.corp.google.com>
Download mbox | patch
Permalink /patch/255226/
State New
Headers show

Comments

Ian Taylor - June 27, 2013, 8:52 p.m.
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

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,