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: multiple errors for a single instance of 'no new variables' #67961

Closed
rsc opened this issue Jun 13, 2024 · 4 comments
Closed

x/tools/gopls: multiple errors for a single instance of 'no new variables' #67961

rsc opened this issue Jun 13, 2024 · 4 comments
Labels
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

@rsc
Copy link
Contributor

rsc commented Jun 13, 2024

What did you do?

% cat x.go
package main

func f() (x, y, z int) {
	x, y := 1, 2
	return
}
% gopls check x.go
Log: Loading packages...
Info: Finished loading packages.
Log: Running...
Info: completed
/Users/rsc/src/rsc.io/gaby/x.go:4:2-14: no new variables on left side of :=
/Users/rsc/src/rsc.io/gaby/x.go:4:7: no new variables on left side of :=
% 

What did you expect to see?

One error.

What did you see instead?

Two errors.

Build info

My x/tools is at golang/tools@7045d2e.

golang.org/x/tools/gopls (devel)
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/[email protected] h1:EfMABMgrJ8+hRjLvhUzJkLKgFv3lYAglGXczg5ggNyk=
    golang.org/x/[email protected] h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
    golang.org/x/[email protected] h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk=
    golang.org/x/[email protected] h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
    golang.org/x/[email protected] => ../
    golang.org/x/[email protected] h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
    honnef.co/go/[email protected] h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
    mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: devel go1.23-d79f51bb9c Sat May 25 14:34:55 2024 -0400
@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 Jun 13, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jun 13, 2024
@gabyhelp
Copy link

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@findleyr
Copy link
Contributor

Thanks. I believe this is a dupe of #65966, but will confirm.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.17.0 Jun 13, 2024
@hyangah
Copy link
Contributor

hyangah commented Jun 14, 2024

In this specific case, one is from compiler and the other is from the nonewvars analyzer.
Does "x/tools/gopls/internal/analysis/nonewvars" still offer a value
if "x/tools/internal/typesinternal" does the check? EDIT: I see. Like #65966, the nonewvars analyzer was to offers fix. In the current gopls architecture, fixes and diagnostics should be exactly paired.

[{
	"resource": "main.go",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": {
		"value": "NoNewVar",
		"target": {
			"$mid": 1,
			"path": "/golang.org/x/tools/internal/typesinternal",
			"scheme": "https",
			"authority": "pkg.go.dev",
			"fragment": "NoNewVar"
		}
	},
	"severity": 8,
	"message": "no new variables on left side of :=",
	"source": "compiler",
	...
}]

[{
	"resource": "main.go",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": {
		"value": "default",
		"target": {
			"$mid": 1,
			"path": "/golang.org/x/tools/gopls/internal/analysis/nonewvars",
			"scheme": "https",
			"authority": "pkg.go.dev"
		}
	},
	"severity": 4,
	"message": "no new variables on left side of :=",
	"source": "nonewvars",
	...
	"tags": [
		1
	]
}]

@findleyr
Copy link
Contributor

Sounds like this is indeed a dupe of #65966. Thanks for confirming, @hyangah!

We need to improve our diagnostic merging logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants