diff --git a/src/go/types/contracts.go b/src/go/types/contracts.go index e5b656ca73..466daed482 100644 --- a/src/go/types/contracts.go +++ b/src/go/types/contracts.go @@ -8,7 +8,6 @@ package types import ( "go/ast" - "sort" ) // TODO(gri) Handling a contract like a type is problematic because it @@ -147,28 +146,11 @@ func (check *Checker) contractType(contr *Contract, e *ast.ContractType) { } // cleanup/complete interfaces - // TODO(gri) should check for duplicate entries in first pass (=> no need for this extra pass) for tpar, iface := range ifaces { if iface == nil { ifaces[tpar] = &emptyInterface } else { - var mset objset - i := 0 - for _, m := range iface.methods { - if m0 := mset.insert(m); m0 != nil { - // A method with the same name exists already. - check.errorf(m.Pos(), "method %s already declared", m.name) - check.reportAltDecl(m0) - } else { - // only keep unique methods - // TODO(gri) revisit this code - introduced to fix large rebase - iface.methods[i] = m - i++ - } - } - iface.methods = iface.methods[:i] - sort.Sort(byUniqueMethodName(iface.methods)) - iface.Complete() + check.completeInterface(iface) } } diff --git a/src/go/types/testdata/contracts.go2 b/src/go/types/testdata/contracts.go2 index 1b6c1c93fc..cd7df220a4 100644 --- a/src/go/types/testdata/contracts.go2 +++ b/src/go/types/testdata/contracts.go2 @@ -19,16 +19,16 @@ type _ contract(A, B, A /* ERROR A redeclared */ ){} contract _(A) { A } /* ERROR expected type */ contract _(A) { A m(); A add(A) int } contract _(A) { B /* ERROR B not declared by contract */ m() } -contract _(A) { A m(); A m /* ERROR already declared */ () } +contract _(A) { A m(); A m /* ERROR duplicate method */ () } contract _(A) { A m() - A m /* ERROR already declared */ () int + A m /* ERROR duplicate method */ () int } contract _(A, B) { A m(x int) B B m(x int) A - A m /* ERROR already declared */ (x int) B - B m /* ERROR already declared */ (x int) B + A m /* ERROR duplicate method */ (x int) B + B m /* ERROR duplicate method */ (x int) B } contract _(A) { diff --git a/src/go/types/type.go b/src/go/types/type.go index bf27599d1b..1a2838a173 100644 --- a/src/go/types/type.go +++ b/src/go/types/type.go @@ -371,8 +371,7 @@ func (t *Interface) Complete() *Interface { case other == nil: methods = append(methods, m) case explicit: - // TODO(gri) enable again once contracts code calls Complete with correct interfaces - // panic("duplicate method " + m.name) + panic("duplicate method " + m.name) default: // check method signatures after all locally embedded interfaces are computed todo = append(todo, m, other.(*Func))