gordonklaus / ineffassign

Detect ineffectual assignments in Go code.
MIT License
390 stars 22 forks source link

Unexpected ineffectual assignment after switch #63

Closed Antonboom closed 2 years ago

Antonboom commented 2 years ago

Hello!

package main

import "fmt"

func returnFalse() bool {
    return false
}

func returnTrue() bool {
    return true
}

func main() {
    isValid := true

    var i interface{} = 100

    switch i.(type) {
    case int:
        isValid = returnFalse()
    default:
        isValid = returnTrue()
    }
    if !isValid {
        fmt.Println("value changed")
    }
}
▶ ineffassign main.go 
/Users/anthony/main.go:14:2: ineffectual assignment to isValid
Antonboom commented 2 years ago

I'm sorry. I didn’t notice which line the linter was pointing to.

Thank u for linter!