This inspection detects potential nil dereferences, taking into account all function calls. The analysis is interprocedural and considers calls across the entire project, including between different packages.

示例:


package a

func CreateUser(name string) *User {
  if isValid(name) {
    return &User{Name: name}
  }
  return nil
}

package main

func main() {
	user := CreateUser("NilDereference")
	print(user.Name) // Potential nil dereference
}

In the provided example, user is a pointer to a User struct, but it can be nil because CreateUser may return nil. Attempting to dereference user to access Name without first checking whether user is nil may result in a runtime error.