gordonklaus / ineffassign

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

false positive: warning: ineffectual assignment to tm #78

Closed Setheck closed 1 year ago

Setheck commented 1 year ago

Kind of interesting because it was reported by https://goreportcard.com/report/github.com/Setheck/dat and reported twice

code is

    var (
        tm     time.Time
        format string
    )
    if opts.Tf {
        tm, format, err = ParseTime(epochstr)
        if err != nil {
            return err
        }
        if name, ok := supportedTimeFormats[format]; ok {
            fmt.Println("detected format:", name)
        } else {
            fmt.Println("failed to detect format.")
        }
        return nil
    } else {
        // validate and convert to time
        tm, err = ParseEpochTime(epochstr, opts.Milliseconds)
        if err != nil {
            return err
        }
    }

    output := buildOutput(tm, opts)
    if opts.Copy {
        if err := clipper.ClipboardHelper.WriteAll(strings.TrimSpace(output)); err != nil {
            return err
        }
    }
gordonklaus commented 1 year ago

A false positive means the assignment is in fact effectual. So, I ask you: where is the value assigned to tm used? (Maybe you overlooked the unconditional return nil?)

Setheck commented 1 year ago

It's passed into buildOutput E: oooh ok this is my mistake. I realize that it's the inner scoped tm. I should have gone to bed earlier 😅