expandTupleArgs converts a function call which argument is a tuple returned by another function into a set of individual call arguments corresponding to tuple elements. For example, for functions defined as: func a() (int, string) {return 42, "foo"} func b(a1 int, a2 string) {} ...the following
(argExprs []ast.Expr)
| 130 | // _tuple := a() |
| 131 | // b(_tuple[0], _tuple[1]) |
| 132 | func (fc *funcContext) expandTupleArgs(argExprs []ast.Expr) []ast.Expr { |
| 133 | if len(argExprs) != 1 { |
| 134 | return argExprs |
| 135 | } |
| 136 | |
| 137 | tuple, isTuple := fc.typeOf(argExprs[0]).(*types.Tuple) |
| 138 | if !isTuple { |
| 139 | return argExprs |
| 140 | } |
| 141 | |
| 142 | tupleVar := fc.newLocalVariable("_tuple") |
| 143 | fc.Printf("%s = %s;", tupleVar, fc.translateExpr(argExprs[0])) |
| 144 | argExprs = make([]ast.Expr, tuple.Len()) |
| 145 | for i := range argExprs { |
| 146 | argExprs[i] = fc.newIdent(fc.formatExpr("%s[%d]", tupleVar, i).String(), tuple.At(i).Type()) |
| 147 | } |
| 148 | return argExprs |
| 149 | } |
| 150 | |
| 151 | func (fc *funcContext) translateArgs(sig *types.Signature, argExprs []ast.Expr, ellipsis bool) []string { |
| 152 | argExprs = fc.expandTupleArgs(argExprs) |
no test coverage detected