compiler: permit duplicate methods from embedded interfaces
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 10 Jan 2020 14:27:05 +0000 (14:27 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 10 Jan 2020 14:27:05 +0000 (14:27 +0000)
    This is a language change for Go 1.14.

    Updates golang/go#6977

    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214240

From-SVN: r280109

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/types.cc
gcc/testsuite/go.test/test/fixedbugs/bug211.go [deleted file]
gcc/testsuite/go.test/test/fixedbugs/bug251.go

index 9189bed5e89d923341dddf5a45cc55a6a209292a..e7f037ac6b895067ecd1770b169b05825a5a42f2 100644 (file)
@@ -1,4 +1,4 @@
-92ee4c2e295fc760105f187f6ea6dc65c81fa892
+98c4c21b52afd6384f9364527bd7f5f9a1c752cf
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 27d53df2c356510193a8d97f7ed77493548cbacc..d6cd326b2e290b344cd7b40efd7b0a8babfa4a78 100644 (file)
@@ -8943,8 +8943,12 @@ Interface_type::finalize_methods()
          continue;
        }
 
+      const Typed_identifier_list* imethods = it->parse_methods_;
+      if (imethods == NULL)
+       continue;
+
       Named_type* nt = t->named_type();
-      if (nt != NULL && it->parse_methods_ != NULL)
+      if (nt != NULL)
        {
          std::vector<Named_type*>::const_iterator q;
          for (q = seen.begin(); q != seen.end(); ++q)
@@ -8960,22 +8964,26 @@ Interface_type::finalize_methods()
          seen.push_back(nt);
        }
 
-      const Typed_identifier_list* imethods = it->parse_methods_;
-      if (imethods == NULL)
-       continue;
       for (Typed_identifier_list::const_iterator q = imethods->begin();
           q != imethods->end();
           ++q)
        {
          if (q->name().empty())
            inherit.push_back(*q);
-         else if (this->find_method(q->name()) == NULL)
-           this->all_methods_->push_back(Typed_identifier(q->name(),
-                                                          q->type(), tl));
          else
-           go_error_at(tl, "inherited method %qs is ambiguous",
-                    Gogo::message_name(q->name()).c_str());
+           {
+             const Typed_identifier* oldm = this->find_method(q->name());
+             if (oldm == NULL)
+               this->all_methods_->push_back(Typed_identifier(q->name(),
+                                                              q->type(), tl));
+             else if (!Type::are_identical(q->type(), oldm->type(),
+                                           Type::COMPARE_TAGS, NULL))
+               go_error_at(tl, "duplicate method %qs",
+                           Gogo::message_name(q->name()).c_str());
+           }
        }
+
+      seen.pop_back();
     }
 
   if (!this->all_methods_->empty())
diff --git a/gcc/testsuite/go.test/test/fixedbugs/bug211.go b/gcc/testsuite/go.test/test/fixedbugs/bug211.go
deleted file mode 100644 (file)
index b150479..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// errorcheck
-
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-type R interface { duplicate() }
-type S interface { duplicate() }
-type T interface { R; S }      // ERROR "duplicate"
-
-func main() {
-}
index 43d9d526fd15b937f529cf654a0c6ead81788c43..706bb8d69019d51d2968a1d13b0911f17ecec973 100644 (file)
@@ -1,18 +1,18 @@
 // errorcheck
 
-// Copyright 2010 The Go Authors.  All rights reserved.
+// Copyright 2010 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
 package main
 
-type I1 interface {
+type I1 interface { // GC_ERROR "invalid recursive type"
        m() I2
        I2 // GCCGO_ERROR "loop|interface"
 }
 
 type I2 interface {
-       I1 // ERROR "loop|interface"
+       I1 // GCCGO_ERROR "loop|interface"
 }