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
gopls/parsing Issues related to parsing / poor parser recovery. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mattmassicotte
Copy link

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 Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jul 31, 2020
@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

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.

@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@stamblerre stamblerre added this to Needs Triage in vscode-go: gopls by default Nov 17, 2020
@stamblerre stamblerre removed this from Needs Triage in vscode-go: gopls by default Dec 2, 2020
@stamblerre stamblerre removed this from the gopls/vscode-go milestone Dec 2, 2020
@stamblerre stamblerre added this to To Do in gopls on-deck Feb 28, 2021
@hyangah hyangah added the gopls/parsing Issues related to parsing / poor parser recovery. label May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/parsing Issues related to parsing / poor parser recovery. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
No open projects
Development

No branches or pull requests

4 participants