mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.84k stars 284 forks source link

False positive with var-declaration #1152

Open rliebz opened 13 hours ago

rliebz commented 13 hours ago

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):

Additional context N/A

chavacava commented 12 hours ago

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

denisvmedia commented 11 hours ago

@chavacava can you please check my PR?

chavacava commented 11 hours ago

@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 commented 11 hours ago

@chavacava yeah, sorry, missed that.