8000 False Positive when using errGroup · Issue #296 · uber-go/nilaway · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
False Positive when using errGroup #296
Open
@QianKuang8

Description

@QianKuang8

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0