diff --git a/go/types/objectpath/objectpath.go b/go/types/objectpath/objectpath.go index e064a1a2926..aa7dfaccf56 100644 --- a/go/types/objectpath/objectpath.go +++ b/go/types/objectpath/objectpath.go @@ -418,7 +418,13 @@ func (enc *Encoder) concreteMethod(meth *types.Func) (Path, bool) { } } - panic(fmt.Sprintf("couldn't find method %s on type %s", meth, named)) + // Due to golang/go#59944, go/types fails to associate the receiver with + // certain methods on cgo types. + // + // TODO(rfindley): replace this panic once golang/go#59944 is fixed in all Go + // versions gopls supports. + return "", false + // panic(fmt.Sprintf("couldn't find method %s on type %s; methods: %#v", meth, named, enc.namedMethods(named))) } // find finds obj within type T, returning the path to it, or nil if not found. diff --git a/gopls/internal/regtest/marker/testdata/fixedbugs/issue59944.txt b/gopls/internal/regtest/marker/testdata/fixedbugs/issue59944.txt new file mode 100644 index 00000000000..118c2df5772 --- /dev/null +++ b/gopls/internal/regtest/marker/testdata/fixedbugs/issue59944.txt @@ -0,0 +1,30 @@ +This test verifies that gopls does not panic when encountering the go/types +bug described in golang/go#59944: the Bindingf function is not included in +the methodset of its receiver type. + +Adapted from the code in question from the issue. + +-- go.mod -- +module example.com + +go 1.12 + +-- cgo.go -- +package x + +import "fmt" + +/* +struct layout { + int field; +}; +*/ +import "C" + +type Layout = C.struct_layout + +// Bindingf is a printf wrapper. This was necessary to trigger the panic in +// objectpath while encoding facts. +func (l *Layout) Bindingf(format string, args ...interface{}) { + fmt.Printf(format, args...) +}