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

Is this unused false positive? #942

Closed
hiromoon opened this issue Mar 5, 2021 · 3 comments
Closed

Is this unused false positive? #942

hiromoon opened this issue Mar 5, 2021 · 3 comments

Comments

@hiromoon
Copy link

@hiromoon hiromoon commented Mar 5, 2021

Hi, I have a question.
Is this a false positive?

Static checker warns unused function.

$ golangci-lint run
foo/example.go:15:16: func `(*Buzz).bar` is unused (unused)
func (b *Buzz) bar() {

This private function is used through interface.

package main

import "./foo"

func main() {
	foo.Bar(&foo.Buzz{})
}
package foo

import "fmt"

type Foo interface {
	bar()
}

func Bar(f Foo) {
	f.bar()
}

type Buzz struct{}

func (b *Buzz) bar() {
	fmt.Println("foo bar buzz")
}

This problem happens with golangci-lint@v1.38.0, not with golangci-lint@v1.37.1.

@hiromoon hiromoon added false-positive needs-triage Newly filed issue that needs triage labels Mar 5, 2021
@dominikh
Copy link
Owner

@dominikh dominikh commented Mar 5, 2021

Can reproduce, looking into it.

@dominikh dominikh added started Issues we've started working on and removed needs-triage Newly filed issue that needs triage labels Mar 5, 2021
@dominikh
Copy link
Owner

@dominikh dominikh commented Mar 5, 2021

This should be fixed on master. I'd like to wait a day or two, to see if this change has caused any new bugs. If it hasn't, I'll make a new patch release.

@hiromoon
Copy link
Author

@hiromoon hiromoon commented Mar 5, 2021

I see! Thank you for quick response!

dominikh added a commit that referenced this issue Mar 9, 2021
In 41bedbd we incorrectly decided
that unused no longer needed to deduplicate types. For the most part,
this was correct. However, it failed to account for pointer types.
go/types does not guarantee that types.NewPointer(T) ==
types.NewPointer(T). This caused parts of the graph to be incorrectly
unreachable.

This commit reverts the aforementioned commit, but puts our custom
Map in its own package, only to be used by the 'unused' check.

Closes gh-942

(cherry picked from commit 9680b43)
@dominikh dominikh removed the started Issues we've started working on label May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants