MCPcopy
hub / github.com/uber-go/nilaway / isErrorReturnNil

Function isErrorReturnNil

assertion/function/assertiontree/backprop_util.go:227–244  ·  view source on GitHub ↗

isErrorReturnNil returns true if the error return is guaranteed to be nil, false otherwise

(rootNode *RootAssertionNode, errRet ast.Expr)

Source from the content-addressed store, hash-verified

225
226// isErrorReturnNil returns true if the error return is guaranteed to be nil, false otherwise
227func isErrorReturnNil(rootNode *RootAssertionNode, errRet ast.Expr) bool {
228 if ident, ok := errRet.(*ast.Ident); ok && rootNode.isNil(ident) {
229 // error return is the literal nil
230 return true
231 }
232
233 // check for false cases where error return value may be nil
234 if asthelper.IsEmptyExpr(errRet) {
235 // error result is a blank named return ("_ error"), so it's always nil
236 return true
237 }
238
239 if exprCallsKnownNilableErrFunc(errRet) {
240 // error value is the return of a known nilable function
241 return true
242 }
243 return false
244}
245
246// isErrorReturnNonnil returns true if the error return is guaranteed to be nonnil, false otherwise
247func isErrorReturnNonnil(rootNode *RootAssertionNode, errRet ast.Expr) bool {

Callers 1

handleErrorReturnsFunction · 0.85

Calls 3

IsEmptyExprFunction · 0.92
isNilMethod · 0.80

Tested by

no test coverage detected