From f2c1c7acf84a6ea8092f3b098de177b3265fbace Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 4 Oct 2018 12:59:09 -0700 Subject: [PATCH] go/types: fix recvPtr helper (follow-up on https://golang.org/cl/139422) The prior CL prepared go/types for the situation where methods might not have a type-checked signature when being looked up. The respective adjustments to recvPtr were not correct (but because so far method signatures are type-checked in time, the bug didn't manifest itself). Updates #23203. Updates #26854. Change-Id: I796691d11e6aac84396bdef802ad30715755fcc6 Reviewed-on: https://go-review.googlesource.com/c/139721 Reviewed-by: Alan Donovan --- src/go/types/methodset.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/go/types/methodset.go b/src/go/types/methodset.go index c25236656e5..619c4484923 100644 --- a/src/go/types/methodset.go +++ b/src/go/types/methodset.go @@ -256,9 +256,12 @@ func (s methodSet) add(list []*Func, index []int, indirect bool, multiples bool) // ptrRecv reports whether the receiver is of the form *T. func ptrRecv(f *Func) bool { - // If a method's type is set, use that as the source of truth for the receiver. - if f.typ != nil { - _, isPtr := deref(f.typ.(*Signature).recv.typ) + // If a method's receiver type is set, use that as the source of truth for the receiver. + // Caution: Checker.funcDecl (decl.go) marks a function by setting its type to an empty + // signature. We may reach here before the signature is fully set up: we must explicitly + // check if the receiver is set (we cannot just look for non-nil f.typ). + if sig, _ := f.typ.(*Signature); sig != nil && sig.recv != nil { + _, isPtr := deref(sig.recv.typ) return isPtr }