]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: fix recvPtr helper (follow-up on https://golang.org/cl/139422)
authorRobert Griesemer <gri@golang.org>
Thu, 4 Oct 2018 19:59:09 +0000 (12:59 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 5 Oct 2018 17:56:05 +0000 (17:56 +0000)
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>
src/go/types/methodset.go

index c25236656e5d7a8153f5521faeea41b6c2078f3a..619c4484923f2bd6c6193a623c9c7a5b993ff6e3 100644 (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
        }