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/parser: bad error message for a badly formed func literal #36750

Open
myitcv opened this issue Jan 24, 2020 · 4 comments
Open

go/parser: bad error message for a badly formed func literal #36750

myitcv opened this issue Jan 24, 2020 · 4 comments
Labels
Milestone

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
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.

@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Mar 12, 2020

Yes, this is is coming from go/parser. A minimal repro can be found here: https://play.golang.org/p/ca24wvyr5Wl. This seems like an instance where go/parser's errors should be updated to match the compiler's. I'll change the issue title to reflect this.

@stamblerre stamblerre changed the title x/tools/gopls: misleading diagnostic for badly formed func literal go/parser: bad error message for a badly formed func literal Mar 12, 2020
@stamblerre stamblerre modified the milestones: gopls/v1.0.0, Unreleased Mar 12, 2020
@toothrot toothrot added the NeedsFix label Mar 12, 2020
@toothrot
Copy link
Contributor

@toothrot toothrot commented Mar 12, 2020

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 6, 2020

Change https://golang.org/cl/259817 mentions this issue: go/parser: Improve error message to user when interface parsing fails

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
5 participants
You can’t perform that action at this time.