1
0
mirror of https://github.com/golang/go synced 2024-09-29 07:14:29 -06:00

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 <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2018-10-04 12:59:09 -07:00
parent 28fa1da9db
commit f2c1c7acf8

View File

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