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:
Alan Donovan 2013-08-01 15:38:41 -04:00
Родитель 5cc33ea5a7
Коммит 61a33ecd43
2 изменённых файлов: 17 добавлений и 2 удалений

Просмотреть файл

@ -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: