mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: add support for generic channels and type conversion during calls
Add support for channels in subster.typ(). Add new test file chans.go. To support assignability of bidirectional channel args to directional channel params, I needed to type check generic calls after they are instantiated. (Eventually, we will create separate functions to just do the assignability logic, so we don't need to call the old typechecker in this case.) So, for generic calls, we now leave the call as OCALL (as a signal that the call still needs typechecking), and do typecheck.Call() during stenciling. Smaller changes: - Set the type of an instantiated OCLOSURE node (and not just the associated OFUNC node) - In instTypeName2, filter out the space that types2.TypeString inserts after a common in a typelist. Our standard naming requires no space after the comma. - With the assignability fix above, I no longer need the explicit conversions in cons.go. Change-Id: I148858bfc6708c0aa3f50bad7debce2b8c8c091f Reviewed-on: https://go-review.googlesource.com/c/go/+/301669 Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
bd6aeca968
commit
dca9c11845
5 changed files with 456 additions and 28 deletions
|
|
@ -138,30 +138,19 @@ func Call(pos src.XPos, typ *types.Type, fun ir.Node, args []ir.Node, dots bool)
|
|||
return n
|
||||
}
|
||||
if fun.Op() != ir.OFUNCINST {
|
||||
// If no type params, still do normal typechecking, since we're
|
||||
// still missing some things done by tcCall below (mainly
|
||||
// typecheckargs and typecheckaste).
|
||||
// If no type params, do normal typechecking, since we're
|
||||
// still missing some things done by tcCall (mainly
|
||||
// typecheckaste/assignconvfn - implementing assignability of args
|
||||
// to params). This will convert OCALL to OCALLFUNC.
|
||||
typecheck.Call(n)
|
||||
return n
|
||||
}
|
||||
|
||||
// Leave the op as OCALL, which indicates the call still needs typechecking.
|
||||
n.Use = ir.CallUseExpr
|
||||
if fun.Type().NumResults() == 0 {
|
||||
n.Use = ir.CallUseStmt
|
||||
}
|
||||
|
||||
// Rewrite call node depending on use.
|
||||
switch fun.Op() {
|
||||
case ir.ODOTINTER:
|
||||
n.SetOp(ir.OCALLINTER)
|
||||
|
||||
case ir.ODOTMETH:
|
||||
n.SetOp(ir.OCALLMETH)
|
||||
|
||||
default:
|
||||
n.SetOp(ir.OCALLFUNC)
|
||||
}
|
||||
|
||||
typed(typ, n)
|
||||
return n
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue