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: unexpected line/character calculations in certain diagnostics #40522

Open
mattmassicotte opened this issue Jul 31, 2020 · 1 comment
Labels

Comments

@mattmassicotte
Copy link

@mattmassicotte mattmassicotte commented Jul 31, 2020

What did you do?

I've run into a situation where gopls was consistently returning a diagnostic with range data that was inconsistent with the editor state. Critically, it was producing a range with a character that was past the end of the line.

While I uncovered the issue interacting with gopls via the LSP interface, it appears to exhibit the behavior on the command line as well. Here's the code that reproduces the issue for me:

package main

func testFunc() error {
	releases := []int{1, 2, 3}

	for _, _ := range releases {
		if ;
	}

	return nil
}

func main() {
	testFunc()
}

What did you expect to see?

The line at issue, which has an intentional error, is the if ;. When running gopls from the command line, I get the following (expected) output:

file.go:8:2: expected operand, found '}'

However if I exchange that offending semi-colon for an r character, I get the following unexpected, and possibly incorrect, output:

file.m:7:7: expected operand, found '}'

Not only is the line change surprising, the character offset is past the end of the line.

What did you see instead?

I would have expected the line/character output to be unchanged, or changed, but still consistent with the length of the line in question.

Build info

golang.org/x/tools/gopls 0.4.3
    golang.org/x/tools/gopls@v0.4.3 h1:irz7Q+XdHNECamFKbNWKvMV2Ak6zBbwdwbZndG4545I=
    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-20200708181441-6004c8539734 h1:Vc0Vx98oU/O3+qPQ36fnTT5UduS55KLh2uSGbL7mqEo=
    golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
    honnef.co/go/tools@v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

Go info

go version go1.13.8 darwin/amd64

@gopherbot gopherbot added this to the Unreleased milestone Jul 31, 2020
@stamblerre stamblerre changed the title x/tools/gopls: Unexpected line/character calculations in certain diagnostics x/tools/gopls: unexpected line/character calculations in certain diagnostics Aug 4, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Aug 4, 2020
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented Aug 4, 2020

Thanks for the report! Confirmed that this is a gopls-specific issue by testing out the error messages coming from go/parser and go/types: https://play.golang.org/p/9RFsdfY3haH.

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.