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

x/tools/gopls: misleading diagnostic for badly formed func literal #36750

Open
myitcv opened this issue Jan 24, 2020 · 1 comment
Open

x/tools/gopls: misleading diagnostic for badly formed func literal #36750

myitcv opened this issue Jan 24, 2020 · 1 comment

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Jan 24, 2020

What version of Go are you using (go version)?

$ go version
go version devel +8e0be05ec7 Sun Jan 19 14:04:09 2020 +0000 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20200121200311-d456b1cd8c86
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.1.8-0.20200121200311-d456b1cd8c86

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/.vim/plugged/govim/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build878422207=/tmp/go-build -gno-record-gcc-switches"

What did you do?

The diagnostic for the following file is misleading:

package main

func main() {
	_ = func(format string, args ...interface) error {
		return nil
	}
}

We get:

PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{
    URI:         "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/main.go",
    Version:     36,
    Diagnostics: {
        {
            Range: protocol.Range{
                Start: protocol.Position{Line:3, Character:5},
                End:   protocol.Position{Line:3, Character:5},
            },
            Severity:           1,
            Code:               nil,
            Source:             "syntax",
            Message:            "expected expression",
            Tags:               nil,
            RelatedInformation: nil,
        },
    },
}

Contrast what we get from the compiler:

./main.go:4:43: syntax error: unexpected ), expecting {
./main.go:5:3: syntax error: unexpected return, expecting comma or )
./main.go:7:1: syntax error: non-declaration statement outside function body

What did you expect to see?

A better diagnostic.

What did you see instead?

Per above

Marking as gopls/v1.0.0 because this isn't critical for v0.3.0.


cc @stamblerre

FYI @leitzler

@myitcv myitcv added this to the gopls/v1.0.0 milestone Jan 24, 2020
@gopherbot gopherbot added the Tools label Jan 24, 2020
@heschik

This comment has been minimized.

Copy link
Contributor

@heschik heschik commented Jan 24, 2020

This would be coming from go/parser or something, no? I don't think gopls can do anything to improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.