type User struct {
Name *string
}
func DumpUserName(user *User) {
// readnil.go:8:8: error: Potential nil panic detected. Observed nil flow from source to dereference point
// readnil.go:8:8: field `Name` dereferenced
a := *user.Name
// readnil.go:9:14: literal `nil` assigned into field `Name`
user.Name = nil
_ = a
}
func DumpUserName2() {
n := "ssss"
u := User{Name: &n}
DumpUserName(&u)
}
Detailed error information
readnil.go:8:8: error: Potential nil panic detected. Observed nil flow from source to dereference point:
readnil.go:9:14: literal nil assigned into field Name
readnil.go:8:8: field Name dereferenced
After dereferencing user.Name and assigning user.Name to nil, I don't think it should throw an error
Detailed error information readnil.go:8:8: error: Potential nil panic detected. Observed nil flow from source to dereference point:
nil
assigned into fieldName
Name
dereferencedAfter dereferencing
user.Name
and assigninguser.Name
tonil
, I don't think it should throw an error