Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit f61c62d

Browse files
committed
Generalise isReturnedWithError
It now recognises any function returning an Error alongside other return values
1 parent 9e4ee0a commit f61c62d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ql/src/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,11 @@ Node extractTupleElement(Node t, int i) {
881881
* For example, `0` in `func tryGetInt() (int, error) { return 0, errors.New("no good") }`
882882
*/
883883
predicate isReturnedWithError(Node node) {
884-
exists(ReturnStmt ret |
885-
ret.getExpr(0) = node.asExpr() and
886-
ret.getNumExpr() = 2 and
887-
ret.getExpr(1).getType() instanceof ErrorType
888-
// That last condition implies ret.getExpr(1) is non-nil, since nil doesn't implement `error`
884+
exists(ReturnStmt ret, int nodeArg, int errorArg |
885+
ret.getExpr(nodeArg) = node.asExpr() and
886+
nodeArg != errorArg and
887+
ret.getExpr(errorArg).getType() instanceof ErrorType
888+
// That last condition implies ret.getExpr(errorArg) is non-nil, since nil doesn't implement `error`
889889
)
890890
}
891891

0 commit comments

Comments
 (0)