Correctly create extract nodes for returns where we cannot infer the type of the returned expression, but know from context that it must be a tuple type.

This commit is contained in:
Max Schaefer
2020-01-15 10:22:29 +00:00
parent 3d508d44e7
commit b7a830593d
2 changed files with 12 additions and 3 deletions

View File

@@ -114,9 +114,14 @@ newtype TControlFlowNode =
)
or
// in a return statement `return f()` where `f` has multiple return values
exists(ReturnStmt ret, CallExpr call | s = ret |
call = ret.getExpr().stripParens() and
exists(call.getType().(TupleType).getComponentType(i))
exists(ReturnStmt ret, SignatureType rettp |
s = ret and
// the return statement has a single expression
exists(ret.getExpr()) and
// but the enclosing function has multiple results
rettp = ret.getEnclosingFunction().getType() and
rettp.getNumResult() > 1 and
exists(rettp.getResultType(i))
)
or
// in a call `f(g())` where `g` has multiple return values

View File

@@ -31,3 +31,7 @@ func test2(x int) (int, int) {
z := x % (1)
return z, y % 13
}
func test3() (x int, y int) {
return unknownFunction()
}