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@7045d2e410bd668db9a552905f25cf86084546f1.
golang.org/x/tools/gopls (devel)
golang.org/x/tools/gopls@(devel)
github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/mod@v0.17.1-0.20240514174713-c0bdc7bd01c9 h1:EfMABMgrJ8+hRjLvhUzJkLKgFv3lYAglGXczg5ggNyk=
golang.org/x/sync@v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/telemetry@v0.0.0-20240521205824-bda55230c457 h1:zf5N6UOrA487eEFacMePxjXAJctxKmyjKUsjA11Uzuk=
golang.org/x/text@v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/tools@v0.18.0 => ../
golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: devel go1.23-d79f51bb9c Sat May 25 14:34:55 2024 -0400
Comment From: gabyhelp
Similar Issues
- https://github.com/golang/go/issues/40020
- https://github.com/golang/go/issues/40030
- https://github.com/golang/go/issues/39999
- https://github.com/golang/go/issues/40087
- https://github.com/golang/go/issues/39995
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: findleyr
Thanks. I believe this is a dupe of #65966, but will confirm.
Comment From: hyangah
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
]
}]
Comment From: findleyr
Sounds like this is indeed a dupe of #65966. Thanks for confirming, @hyangah!
We need to improve our diagnostic merging logic.