OSDN Git Service

Don't look up methods for pointer to interface.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 26 Mar 2011 19:04:54 +0000 (19:04 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 26 Mar 2011 19:04:54 +0000 (19:04 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171562 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/types.cc
gcc/testsuite/go.test/test/hashmap.go

index 6ca22cb..6feb035 100644 (file)
@@ -7995,7 +7995,7 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr,
 
   const Named_type* nt = type->deref()->named_type();
   const Struct_type* st = type->deref()->struct_type();
-  const Interface_type* it = type->deref()->interface_type();
+  const Interface_type* it = type->interface_type();
 
   // If this is a pointer to a pointer, then it is possible that the
   // pointed-to type has methods.
@@ -8011,7 +8011,6 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr,
        return Expression::make_error(location);
       nt = type->points_to()->named_type();
       st = type->points_to()->struct_type();
-      it = type->points_to()->interface_type();
     }
 
   bool receiver_can_be_pointer = (expr->type()->points_to() != NULL
@@ -8164,7 +8163,7 @@ Type::find_field_or_method(const Type* type,
     }
 
   // Interface types can have methods.
-  const Interface_type* it = type->deref()->interface_type();
+  const Interface_type* it = type->interface_type();
   if (it != NULL && it->find_method(name) != NULL)
     {
       *is_method = true;
@@ -8326,12 +8325,12 @@ Type::is_unexported_field_or_method(Gogo* gogo, const Type* type,
        }
     }
 
-  type = type->deref();
-
   const Interface_type* it = type->interface_type();
   if (it != NULL && it->is_unexported_method(gogo, name))
     return true;
 
+  type = type->deref();
+
   const Struct_type* st = type->struct_type();
   if (st != NULL && st->is_unexported_local_field(gogo, name))
     return true;
index 096ece0..0a4d7ab 100755 (executable)
@@ -21,7 +21,7 @@ func ASSERT(p bool) {
 
 type KeyType interface {
        Hash() uint32
-       Match(other *KeyType) bool
+       Match(other KeyType) bool
 }
 
 
@@ -31,8 +31,8 @@ type ValueType interface {
 
 
 type Entry struct {
-       key *KeyType
-       value *ValueType
+       key KeyType
+       value ValueType
 }
 
 
@@ -68,7 +68,7 @@ func (m *HashMap) Initialize (initial_log2_capacity uint32) {
 }
 
 
-func (m *HashMap) Probe (key *KeyType) *Entry {
+func (m *HashMap) Probe (key KeyType) *Entry {
        ASSERT(key != nil)
 
        var i uint32 = key.Hash() % m.capacity()
@@ -86,7 +86,7 @@ func (m *HashMap) Probe (key *KeyType) *Entry {
 }
 
 
-func (m *HashMap) Lookup (key *KeyType, insert bool) *Entry {
+func (m *HashMap) Lookup (key KeyType, insert bool) *Entry {
        // Find a matching entry.
        var p *Entry = m.Probe(key)
                if p.key != nil {
@@ -145,7 +145,7 @@ func (n *Number) Hash() uint32 {
 }
 
 
-func (n *Number) Match(other *KeyType) bool {
+func (n *Number) Match(other KeyType) bool {
        // var y *Number = other
        // return n.x == y.x
        return false