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

mattmassicotte opened this issue Jul 31, 2020 · 1 comment


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() {

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 0.4.3 h1:irz7Q+XdHNECamFKbNWKvMV2Ak6zBbwdwbZndG4545I= h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= h1:Vc0Vx98oU/O3+qPQ36fnTT5UduS55KLh2uSGbL7mqEo= h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8= 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
Copy link

@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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.