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

False positive with var-declaration #1152

Closed
rliebz opened this issue Dec 1, 2024 · 6 comments · Fixed by #1154
Closed

False positive with var-declaration #1152

rliebz opened this issue Dec 1, 2024 · 6 comments · Fixed by #1154
Assignees
Labels

Comments

@rliebz
Copy link
Contributor

rliebz commented Dec 1, 2024

Describe the bug
The var-declaration check incorrectly warns if explicitly assigning a zero value in a var declaration, even if the zero value being assigned isn't the default for a variable of that type.

To Reproduce
Steps to reproduce the behavior:

  1. I updated revive go install github.com/mgechev/revive@latest
  2. I run it with the following flags:
revive main.go

main.go:

// Package main is a package.
package main

func main() {
	var a any = 0
	_ = a

	var b any = ""
	_ = b
}

Expected behavior
I would expect no errors for var-declaration, because the zero value for a variable of type any is nil, not 0 or "".

Logs

main.go:5:14: should drop = 0 from declaration of var a; it is the zero value
main.go:8:14: should drop = "" from declaration of var b; it is the zero value

Desktop (please complete the following information):

  • OS: macOS 15.1.1
  • Version of Go: go version go1.23.3 darwin/arm64

Additional context
N/A

@chavacava
Copy link
Collaborator

Hi @rliebz thanks for reporting the problem. I'll take a look

@denisvmedia
Copy link
Collaborator

@chavacava can you please check my PR?

@chavacava
Copy link
Collaborator

chavacava commented Dec 1, 2024

@chavacava can you please check my PR?

Yes, no problem but please in the future assign you the issue before start working on it.

@denisvmedia denisvmedia assigned denisvmedia and unassigned chavacava Dec 1, 2024
@denisvmedia
Copy link
Collaborator

@chavacava yeah, sorry, missed that.

@denisvmedia
Copy link
Collaborator

@rliebz please check with my updates merged.

@rliebz
Copy link
Contributor Author

rliebz commented Dec 2, 2024

Confirmed fixed, thanks for the quick response time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants