nilaway
nilaway copied to clipboard
Support validator patterns
NilAway currently does not track the side effects of validator functions:
//nilable(a)
func validate(a *int) bool {
return a != nil
}
//nilable(a)
func foo(a *int) {
if validate(a) {
// `a` should be nonnil now.
print(*a)
}
}
But NilAway complains
unexpected diagnostic: Potential nil panic detected. Observed nil flow from source to dereference point:
- foo.go:31:10: function parameter `a` dereferenced
It could also be the case that the validate function validates certain fields of a struct and returns a boolean variable. Tracking this kind of side effects could be expensive, and we should think of a smart way to handle this in an efficient manner.