uber-go / nilaway

Static analysis tool to detect potential nil panics in Go code
Apache License 2.0
2.91k stars 54 forks source link

False positive result #246

Open potalestor opened 1 month ago

potalestor commented 1 month ago
package main

import "fmt"

type S struct{}

type SS []*S

type C struct{}

type CC []*C

func (ss SS) Convert() CC {
    cc := make(CC, len(ss))
    for i := range ss {
        cc[i] = &C{}
    }

    return cc
}

func main() {
    var ss SS

    fmt.Println(ss.Convert())
}
sonalmahajan15 commented 1 month ago

@potalestor, this seems to be a corner case that is not correctly handled for named type receivers. We'll add a fix for it soon. Thanks for reporting!