Commit 2fb672a2 by Ian Lance Taylor

compiler: permit duplicate methods from embedded interfaces

    
    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
parent 9c158322
92ee4c2e295fc760105f187f6ea6dc65c81fa892 98c4c21b52afd6384f9364527bd7f5f9a1c752cf
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -8943,8 +8943,12 @@ Interface_type::finalize_methods() ...@@ -8943,8 +8943,12 @@ Interface_type::finalize_methods()
continue; continue;
} }
const Typed_identifier_list* imethods = it->parse_methods_;
if (imethods == NULL)
continue;
Named_type* nt = t->named_type(); Named_type* nt = t->named_type();
if (nt != NULL && it->parse_methods_ != NULL) if (nt != NULL)
{ {
std::vector<Named_type*>::const_iterator q; std::vector<Named_type*>::const_iterator q;
for (q = seen.begin(); q != seen.end(); ++q) for (q = seen.begin(); q != seen.end(); ++q)
...@@ -8960,24 +8964,28 @@ Interface_type::finalize_methods() ...@@ -8960,24 +8964,28 @@ Interface_type::finalize_methods()
seen.push_back(nt); 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(); for (Typed_identifier_list::const_iterator q = imethods->begin();
q != imethods->end(); q != imethods->end();
++q) ++q)
{ {
if (q->name().empty()) if (q->name().empty())
inherit.push_back(*q); inherit.push_back(*q);
else if (this->find_method(q->name()) == NULL) else
{
const Typed_identifier* oldm = this->find_method(q->name());
if (oldm == NULL)
this->all_methods_->push_back(Typed_identifier(q->name(), this->all_methods_->push_back(Typed_identifier(q->name(),
q->type(), tl)); q->type(), tl));
else else if (!Type::are_identical(q->type(), oldm->type(),
go_error_at(tl, "inherited method %qs is ambiguous", Type::COMPARE_TAGS, NULL))
go_error_at(tl, "duplicate method %qs",
Gogo::message_name(q->name()).c_str()); Gogo::message_name(q->name()).c_str());
} }
} }
seen.pop_back();
}
if (!this->all_methods_->empty()) if (!this->all_methods_->empty())
this->all_methods_->sort_by_name(); this->all_methods_->sort_by_name();
else else
......
// 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() {
}
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
package main package main
type I1 interface { type I1 interface { // GC_ERROR "invalid recursive type"
m() I2 m() I2
I2 // GCCGO_ERROR "loop|interface" I2 // GCCGO_ERROR "loop|interface"
} }
type I2 interface { type I2 interface {
I1 // ERROR "loop|interface" I1 // GCCGO_ERROR "loop|interface"
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment