aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/call.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-03-30 22:07:26 -0700
committerRobert Griesemer <gri@golang.org>2021-04-06 18:59:08 +0000
commit3a30381b2110f15de85514609965b7cafd90aec0 (patch)
tree2c298ee9dba09987d66d59373ba759122d589a96 /src/cmd/compile/internal/types2/call.go
parent93466cc1b697836200e73bb103522324d38e894f (diff)
downloadgo-3a30381b2110f15de85514609965b7cafd90aec0.tar.gz
go-3a30381b2110f15de85514609965b7cafd90aec0.zip
cmd/compile/internal/types2: simplify Checker.funcInst
Now that we use square brackets for instantiations, we can tell type arguments from ordinary arguments without "guessing" which permits a simpler implementation. While at it, also fix a minor position error for type instantiations (now matching the code for function instantiations). Change-Id: I20eca51c5b06259703767b5906e89197d6cd595a Reviewed-on: https://go-review.googlesource.com/c/go/+/306169 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/call.go')
-rw-r--r--src/cmd/compile/internal/types2/call.go36
1 files changed, 9 insertions, 27 deletions
diff --git a/src/cmd/compile/internal/types2/call.go b/src/cmd/compile/internal/types2/call.go
index 18737e45a0..38e9015248 100644
--- a/src/cmd/compile/internal/types2/call.go
+++ b/src/cmd/compile/internal/types2/call.go
@@ -15,39 +15,29 @@ import (
// funcInst type-checks a function instantiaton inst and returns the result in x.
// The operand x must be the evaluation of inst.X and its type must be a signature.
func (check *Checker) funcInst(x *operand, inst *syntax.IndexExpr) {
- args, ok := check.exprOrTypeList(unpackExpr(inst.Index))
- if !ok {
+ xlist := unpackExpr(inst.Index)
+ targs := check.typeList(xlist)
+ if targs == nil {
x.mode = invalid
x.expr = inst
return
}
- if len(args) > 0 && args[0].mode != typexpr {
- check.errorf(args[0], "%s is not a type", args[0])
- ok = false
- }
+ assert(len(targs) == len(xlist))
// check number of type arguments
- n := len(args)
+ n := len(targs)
sig := x.typ.(*Signature)
if !check.conf.InferFromConstraints && n != len(sig.tparams) || n > len(sig.tparams) {
- check.errorf(args[n-1], "got %d type arguments but want %d", n, len(sig.tparams))
+ check.errorf(xlist[n-1], "got %d type arguments but want %d", n, len(sig.tparams))
x.mode = invalid
x.expr = inst
return
}
- // collect types
- targs := make([]Type, n)
+ // determine argument positions (for error reporting)
poslist := make([]syntax.Pos, n)
- for i, a := range args {
- if a.mode != typexpr {
- // error was reported earlier
- x.mode = invalid
- x.expr = inst
- return
- }
- targs[i] = a.typ
- poslist[i] = a.Pos()
+ for i, x := range xlist {
+ poslist[i] = syntax.StartPos(x)
}
// if we don't have enough type arguments, use constraint type inference
@@ -82,14 +72,6 @@ func (check *Checker) funcInst(x *operand, inst *syntax.IndexExpr) {
assert(n == len(sig.tparams))
// instantiate function signature
- for i, typ := range targs {
- // some positions may be missing if types are inferred
- var pos syntax.Pos
- if i < len(poslist) {
- pos = poslist[i]
- }
- check.ordinaryType(pos, typ)
- }
res := check.instantiate(x.Pos(), sig, targs, poslist).(*Signature)
assert(res.tparams == nil) // signature is not generic anymore
if inferred {