Skip to content

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

Closed as not planned

Description

@rsc

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/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

Activity

  1. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    goplsIssues related to the Go language server, gopls.
    on Jun 13, 2024
  2. added this to the Unreleased milestone on Jun 13, 2024
  3. gabyhelp commented on Jun 13, 2024

    @gabyhelp
  4. findleyr commented on Jun 13, 2024

    @findleyr
    Contributor

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

  5. hyangah commented on Jun 14, 2024

    @hyangah
    Contributor

    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
    	]
    }]
    
  6. findleyr commented on Jun 14, 2024

    @findleyr
    Contributor

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

    We need to improve our diagnostic merging logic.

  7. locked and limited conversation to collaborators on Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions