From 61a33ecd43ff7fef03e020d759dd542085e0c551 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 1 Aug 2013 15:38:41 -0400 Subject: [PATCH] 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 --- go/types/call.go | 6 +++++- ssa/sanity.go | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/go/types/call.go b/go/types/call.go index f0798e8a1..6b9146990 100644 --- a/go/types/call.go +++ b/go/types/call.go @@ -305,7 +305,11 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) { } x.mode = value - x.typ = obj.typ + + // remove receiver + sig := *obj.typ.(*Signature) + sig.recv = nil + x.typ = &sig default: unreachable() diff --git a/ssa/sanity.go b/ssa/sanity.go index 8869befa2..177d8a427 100644 --- a/ssa/sanity.go +++ b/ssa/sanity.go @@ -37,6 +37,7 @@ func sanityCheck(fn *Function, reporter io.Writer) bool { // func mustSanityCheck(fn *Function, reporter io.Writer) { if !sanityCheck(fn, reporter) { + fn.DumpTo(os.Stderr) panic("SanityCheck failed") } } @@ -141,7 +142,17 @@ func (s *sanity) checkInstr(idx int, instr Instruction) { case *Lookup: case *MakeChan: 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 *MakeMap: case *MakeSlice: