diff options
author | Rebecca Stambler <rstambler@golang.org> | 2020-04-24 01:01:48 -0400 |
---|---|---|
committer | Rebecca Stambler <rstambler@golang.org> | 2020-04-24 18:49:16 +0000 |
commit | 512277dc19b918da19e083c28427109256ef9309 (patch) | |
tree | 44cfc1d3d5dc3921634fc50cef5dc125ced42217 /src/go/types/expr.go | |
parent | da33f9c78a89c0997269a77e134127c135583963 (diff) | |
download | go-512277dc19b918da19e083c28427109256ef9309.tar.gz go-512277dc19b918da19e083c28427109256ef9309.zip |
go/types: improve error message for pointer receiver errors
The compiler produces high quality error messages when an interface is
implemented by *T, rather than T. This change improves the analogous
error messages in go/types, from "missing method X" to "missing method
X (X has pointer receiver)".
I am open to improving this message further - I didn't copy the compiler
error message exactly because, at one of the call sites of
(*check).missingMethod, we no longer have access to the name of the
interface.
Fixes golang/go#36336
Change-Id: Ic4fc38b13fff9e5d9a69cc750c21e0b0c34d85a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/229801
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go/types/expr.go')
-rw-r--r-- | src/go/types/expr.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go index f88b2389c6..d1e892a9b7 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1566,10 +1566,13 @@ func (check *Checker) typeAssertion(pos token.Pos, x *operand, xtyp *Interface, if method == nil { return } - var msg string if wrongType != nil { - msg = fmt.Sprintf("wrong type for method %s (have %s, want %s)", method.name, wrongType.typ, method.typ) + if check.identical(method.typ, wrongType.typ) { + msg = fmt.Sprintf("missing method %s (%s has pointer receiver)", method.name, method.name) + } else { + msg = fmt.Sprintf("wrong type for method %s (have %s, want %s)", method.name, wrongType.typ, method.typ) + } } else { msg = "missing method " + method.name } |