Open
Description
Nilaway fail to get the correct answer when using errgroup(case1). But it works fine in normal case(case2).
package main
import (
"context"
"fmt"
"golang.org/x/sync/errgroup"
)
func getData(s string) (*string, error) {
if s == "" {
return nil, fmt.Errorf("empty data")
}
return &s, nil
}
// Not OK
func case1() {
g, _ := errgroup.WithContext(context.Background())
var s *string
g.Go(func() error {
var err error
s, err = getData("hello")
if err != nil {
return err
}
return nil
})
if err := g.Wait(); err != nil {
return
}
fmt.Println(*s)
}
// OK
func case2() {
var s *string
var err error
s, err = getData("hello")
if err != nil {
return
}
fmt.Println(*s)
}
func main() {
case1()
case2()
}
// error: Potential nil panic detected. Observed nil flow from source to dereference point:
// - hello_world/main.go:30:15: unassigned variable `s` dereferenced
Metadata
Metadata
Assignees
Labels
No labels