mirror of https://github.com/golang/go.git
go/types: use new Checker.completeInterface when constructing Contracts
Change-Id: I1b54ddb7ac69541fcab1f17e0fe1574288a5b9b9
This commit is contained in:
parent
0ac0b8518c
commit
7b6471a756
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue