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: wrong quick fix suggestion QF1011 #47815

Closed
jackieli-tes opened this issue Aug 19, 2021 · 5 comments
Closed

x/tools/gopls: wrong quick fix suggestion QF1011 #47815

jackieli-tes opened this issue Aug 19, 2021 · 5 comments
Labels
FrozenDueToAge 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

@jackieli-tes
Copy link

What did you do?

playground link

package main

import (
	"fmt"
	"math"
)

func main() {
	var f float32 = math.MaxFloat32
	fmt.Println("Hello, playground", f)
}

suggests:

[QF1011] [H] could omit type float32 from declaration; it will be inferred from the right-hand side

What did you expect to see?

No quick fix. f should have float32 otherwise it'll because float64

What did you see instead?

[QF1011] [H] could omit type float32 from declaration; it will be inferred from the right-hand side

after applying it becomes:

var f = math.MaxFloat32

Build info

golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/google/go-cmp@v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
    golang.org/x/tools@v0.1.0 => ../
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.0 h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=
    mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=
@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 Aug 19, 2021
@gopherbot gopherbot added this to the Unreleased milestone Aug 19, 2021
@ShoshinNikita
Copy link

I think it's a staticcheck issue

@dominikh
Copy link
Member

Yes, that's a Staticcheck bug. I've filed dominikh/go-tools#1071

@findleyr
Copy link
Contributor

I think it's actually likely that this is not a staticcheck bug. I didn't have time to fully investigate, but on a hunch I tried making gopls fully type check everything (rather than filter the AST for imported packages outside of the workspace), and the bug went away.

What I didn't understand is why this particular bug would manifest. This needs to be investigated further on the gopls side.

@dominikh
Copy link
Member

@findleyr I could reproduce it with the staticcheck binary, so I think it's a Staticcheck bug.

$ cat sand.go 
package main

const X = 1

func main() {
	var _ uint = X
}
$ staticcheck -debug.run-quickfix-analyzers
sand.go:6:8: could omit type uint from declaration; it will be inferred from the right-hand side (QF1011)

@findleyr
Copy link
Contributor

@dominikh ah ok, then I suppose I need to look into why it didn't repro with my hacked-up gopls :)

Going to close this in favor of the staticcheck issue.

@golang golang locked and limited conversation to collaborators Aug 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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