8000 False Positive when error is not returned from function · Issue #295 · uber-go/nilaway · GitHub
[go: up one dir, main page]

Skip to content

False Positive when error is not returned from function #295

Open

Description

@QianKuang8

Case 1 use switch and case 2 use if. Both of them are failed.

package main

import "fmt"

// not OK
func case1() {
	var s *string
	var err error
	situation := 1
	switch situation {
	case 1:
		tmp := "one"
		s = &tmp
	default:
		err = fmt.Errorf("error")
	}
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(*s)
}

// not OK
func case2() {
	var s *string
	var err error
	situation := 1
	if situation == 1 {
		tmp := "one"
		s = &tmp
	} else {
		err = fmt.Errorf("error")
	}
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(*s)
}

func main() {
	case1()
	case2()
}

I check the issues and this is similar to #110 but more simple with a bit different.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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