compiler: structs inherit all methods from embedded pointer fields.
authorIan Lance Taylor <ian@gcc.gnu.org>
Thu, 27 Jun 2013 20:51:55 +0000 (20:51 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Thu, 27 Jun 2013 20:51:55 +0000 (20:51 +0000)
Previously if a struct S contained an embedded field *T,
a method with receiver *T would not be promoted to a method
with value receiver S.

From-SVN: r200493

gcc/go/gofrontend/types.cc

index 3fe20904493b6e152660224b6beac415960fb76d..0a86d4720626578997b4fd64056a146dc8389e47 100644 (file)
@@ -9396,13 +9396,18 @@ Type::find_field_or_method(const Type* type,
        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,