Skip to content

Commit f2c1c7a

Browse files
committed
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 <[email protected]>
1 parent 28fa1da commit f2c1c7a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/go/types/methodset.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,12 @@ func (s methodSet) add(list []*Func, index []int, indirect bool, multiples bool)
256256

257257
// ptrRecv reports whether the receiver is of the form *T.
258258
func ptrRecv(f *Func) bool {
259-
// If a method's type is set, use that as the source of truth for the receiver.
260-
if f.typ != nil {
261-
_, isPtr := deref(f.typ.(*Signature).recv.typ)
259+
// If a method's receiver type is set, use that as the source of truth for the receiver.
260+
// Caution: Checker.funcDecl (decl.go) marks a function by setting its type to an empty
261+
// signature. We may reach here before the signature is fully set up: we must explicitly
262+
// check if the receiver is set (we cannot just look for non-nil f.typ).
263+
if sig, _ := f.typ.(*Signature); sig != nil && sig.recv != nil {
264+
_, isPtr := deref(sig.recv.typ)
262265
return isPtr
263266
}
264267

0 commit comments

Comments
 (0)