For f(g()) calls where g() is multi-valued, we may need to insert
implicit conversions to convert g()'s result values to f()'s parameter
types. This CL refactors code slightly so this will be easier to
handle.
Change-Id: I3a432220dcb62daecf9a66030e8fa1f097e95f95
Reviewed-on: https://go-review.googlesource.com/c/go/+/413362
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
fun = typecheck.Callee(ir.NewSelectorExpr(pos, ir.OXDOT, fun, sym))
}
pos := r.pos()
- args := r.exprs()
- dots := r.Bool()
+ var args ir.Nodes
+ var dots bool
+ if r.Bool() { // f(g())
+ call := r.expr()
+ args = []ir.Node{call}
+ } else {
+ args = r.exprs()
+ dots = r.Bool()
+ }
n := typecheck.Call(pos, fun, args, dots)
switch n.Op() {
case ir.OAPPEND:
w.Code(exprCall)
writeFunExpr()
w.pos(expr)
- w.exprs(expr.ArgList)
- w.Bool(expr.HasDots)
+ if w.Bool(len(expr.ArgList) == 1 && isMultiValueExpr(w.p.info, expr.ArgList[0])) {
+ // f(g()) call
+ assert(!expr.HasDots)
+ w.expr(expr.ArgList[0])
+ } else {
+ w.exprs(expr.ArgList)
+ w.Bool(expr.HasDots)
+ }
}
}
return false
}
+// isMultiValueExpr reports whether expr is a function call expression
+// that yields multiple values.
+func isMultiValueExpr(info *types2.Info, expr syntax.Expr) bool {
+ tv, ok := info.Types[expr]
+ assert(ok)
+ assert(tv.IsValue())
+ if tuple, ok := tv.Type.(*types2.Tuple); ok {
+ assert(tuple.Len() > 1)
+ return true
+ }
+ return false
+}
+
// recvBase returns the base type for the given receiver parameter.
func recvBase(recv *types2.Var) *types2.Named {
typ := recv.Type()