зеркало из https://github.com/golang/tools.git
go.tools/go/types: fix: the type of a method value should not have a reciever
e.g. type T int func (T) f() {} var t T _ = t.f // method value: should have signature "func()", no receiver Also: - ssa: add sanity check that helped diagnose this. R=gri CC=golang-dev https://golang.org/cl/12283043
This commit is contained in:
Родитель
5cc33ea5a7
Коммит
61a33ecd43
|
@ -305,7 +305,11 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
x.mode = value
|
x.mode = value
|
||||||
x.typ = obj.typ
|
|
||||||
|
// remove receiver
|
||||||
|
sig := *obj.typ.(*Signature)
|
||||||
|
sig.recv = nil
|
||||||
|
x.typ = &sig
|
||||||
|
|
||||||
default:
|
default:
|
||||||
unreachable()
|
unreachable()
|
||||||
|
|
|
@ -37,6 +37,7 @@ func sanityCheck(fn *Function, reporter io.Writer) bool {
|
||||||
//
|
//
|
||||||
func mustSanityCheck(fn *Function, reporter io.Writer) {
|
func mustSanityCheck(fn *Function, reporter io.Writer) {
|
||||||
if !sanityCheck(fn, reporter) {
|
if !sanityCheck(fn, reporter) {
|
||||||
|
fn.DumpTo(os.Stderr)
|
||||||
panic("SanityCheck failed")
|
panic("SanityCheck failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +142,17 @@ func (s *sanity) checkInstr(idx int, instr Instruction) {
|
||||||
case *Lookup:
|
case *Lookup:
|
||||||
case *MakeChan:
|
case *MakeChan:
|
||||||
case *MakeClosure:
|
case *MakeClosure:
|
||||||
// TODO(adonovan): check FreeVars count matches.
|
numFree := len(instr.Fn.(*Function).FreeVars)
|
||||||
|
numBind := len(instr.Bindings)
|
||||||
|
if numFree != numBind {
|
||||||
|
s.errorf("MakeClosure has %d Bindings for function %s with %d free vars",
|
||||||
|
numBind, instr.Fn, numFree)
|
||||||
|
|
||||||
|
}
|
||||||
|
if recv := instr.Type().(*types.Signature).Recv(); recv != nil {
|
||||||
|
s.errorf("MakeClosure's type includes receiver %s", recv.Type())
|
||||||
|
}
|
||||||
|
|
||||||
case *MakeInterface:
|
case *MakeInterface:
|
||||||
case *MakeMap:
|
case *MakeMap:
|
||||||
case *MakeSlice:
|
case *MakeSlice:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче