diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2022-06-21 11:31:11 -0700 |
|---|---|---|
| committer | Matthew Dempsky <mdempsky@google.com> | 2022-06-23 21:55:01 +0000 |
| commit | 711dacd8cf52d0c06624c4af3563d3b728c50b57 (patch) | |
| tree | a8398773572ffe20487f1bfbff491e84e9b1ced2 /src/cmd/compile/internal/noder | |
| parent | 46b01ec667c05fb8eb8f382b173e126282acd80c (diff) | |
| download | go-711dacd8cf52d0c06624c4af3563d3b728c50b57.tar.xz | |
[dev.unified] cmd/compile/internal/noder: implicit conversion of call arguments
Function call arguments need to be implicitly converted to their
respective parameter types. This CL updates the Unified IR writer to
handle this case, at least for typical function calls. I'll handle
f(g()) calls is a subsequent CL.
Change-Id: I7c031d21f57885c9516eaf89eca517977bf9e39a
Reviewed-on: https://go-review.googlesource.com/c/go/+/413514
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder')
| -rw-r--r-- | src/cmd/compile/internal/noder/writer.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index e773b8973d..5160cfaac6 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -1519,6 +1519,9 @@ func (w *writer) expr(expr syntax.Expr) { w.Bool(false) // not a method call (i.e., normal function call) } + sigType := types2.CoreType(tv.Type).(*types2.Signature) + paramTypes := sigType.Params() + w.Code(exprCall) writeFunExpr() w.pos(expr) @@ -1527,7 +1530,20 @@ func (w *writer) expr(expr syntax.Expr) { assert(!expr.HasDots) w.expr(expr.ArgList[0]) // TODO(mdempsky): Implicit conversions to parameter types. } else { - w.exprs(expr.ArgList) // TODO(mdempsky): Implicit conversions to parameter types. + // Like w.exprs(expr.ArgList), but with implicit conversions to parameter types. + args := expr.ArgList + w.Sync(pkgbits.SyncExprs) + w.Len(len(args)) + for i, arg := range args { + var paramType types2.Type + if sigType.Variadic() && !expr.HasDots && i+1 >= paramTypes.Len() { + paramType = paramTypes.At(paramTypes.Len() - 1).Type().(*types2.Slice).Elem() + } else { + paramType = paramTypes.At(i).Type() + } + w.implicitExpr(expr, paramType, arg) + } + w.Bool(expr.HasDots) } } |
