Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types: pointer method error less useful than the compiler's #38658

Closed
atombender opened this issue Apr 25, 2020 · 3 comments
Closed

go/types: pointer method error less useful than the compiler's #38658

atombender opened this issue Apr 25, 2020 · 3 comments
Milestone

Comments

@atombender
Copy link

What did you do?

I was very confused with what was wrong with my code:

Screen Shot 2020-04-25 at 15 11 57

Since gopls frequently errors out for whatever reason, I decided to check what go build says:

Screen Shot 2020-04-25 at 15 12 13

The object here is a zerolog.Logger (from zerolog), which provides Warn on a pointer receiver.

What did you expect to see?

Compiler error should be same as what go build gives.

What did you see instead?

Wrong compiler error.

Build info

golang.org/x/tools/gopls 0.4.0
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
    golang.org/x/sync@v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
    golang.org/x/tools@v0.0.0-20200407041343-bf15fae40dea => ../
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info

go version go1.14 darwin/amd64

@gopherbot gopherbot added this to the Unreleased milestone Apr 25, 2020
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Apr 25, 2020
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@stamblerre
Copy link
Contributor

Ah, thanks for reporting! This is another instance of a go/types error differing from a compiler error. I'll try to get a fix in for 1.15.

@stamblerre stamblerre changed the title x/tools/gopls: Error differs from "go build" go/types: pointer method error less useful than the compiler's Apr 26, 2020
@stamblerre stamblerre removed Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Apr 26, 2020
@stamblerre stamblerre modified the milestones: Unreleased, Go1.15 Apr 26, 2020
@stamblerre stamblerre self-assigned this Apr 26, 2020
@gopherbot
Copy link

Change https://golang.org/cl/230380 mentions this issue: go/types: improve errors for method calls with pointer receivers

xujianhai666 pushed a commit to xujianhai666/go-1 that referenced this issue May 21, 2020
The compiler has better error messages for methods called without a
pointer receiver when one is expected. This change is similar to
CL 229801, but for method calls.

Also, added better error messages for functions called with the wrong
capitalization. I left the third TODO in this switch statement almost
as-is because I'm not sure that the extra complexity is worth it -
I adjusted the error to look like the one the compiler reports.

Fixes golang#38658

Change-Id: Ie0ca2503e12f3659f112f0135cc27db1b027fdcb
Reviewed-on: https://go-review.googlesource.com/c/go/+/230380
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@golang golang locked and limited conversation to collaborators Apr 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants