❌ Error case (a.New from another package):
// a/a.go
type A struct {
V int
}
func New() (*A, error) {
a := &A{}
if rand.Int()%2 == 0 {
return a, errors.New("random error")
}
return a, nil
}
// b.go
func test() {
x, _ := a.New()
print(x.V) // nilaway reports an error
}
✅ No error case (New in the same package):
type A struct {
V int
}
func New() (*A, error) {
a := &A{}
if rand.Int()%2 == 0 {
return a, errors.New("random error")
}
return a, nil
}
func test() {
x, _ := New()
print(x.V) // nilaway does NOT report an error
}