Per feedback from prior CL.
Change-Id: Icbf6149c3b61e26085caf6f368d22ad4f02c75fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/480316
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
)
// funcInst type-checks a function instantiation and returns the result in x.
-// The incoming x must be an uninstantiated generic function. If inst != 0,
+// The incoming x must be an uninstantiated generic function. If inst != nil,
// it provides (some or all of) the type arguments (inst.Index) for the
-// instantiation. If the target type T != nil and is a (non-generic) function
-// signature, the signature's parameter types are used to infer additional
-// missing type arguments of x, if any.
-// At least one of inst or T must be provided.
-func (check *Checker) funcInst(T Type, pos syntax.Pos, x *operand, inst *syntax.IndexExpr) {
+// instantiation. If the target type tsig != nil, the signature's parameter
+// types are used to infer additional missing type arguments of x, if any.
+// At least one of tsig or inst must be provided.
+func (check *Checker) funcInst(tsig *Signature, pos syntax.Pos, x *operand, inst *syntax.IndexExpr) {
+ assert(tsig != nil || inst != nil)
+
if !check.allowVersion(check.pkg, 1, 18) {
check.versionErrorf(inst.Pos(), "go1.18", "function instantiation")
}
- // tsig is the (assignment) target function signature, or nil.
- // TODO(gri) refactor and pass in tsig to funcInst instead
- var tsig *Signature
- if check.conf.EnableReverseTypeInference && T != nil {
- tsig, _ = under(T).(*Signature)
- }
-
// targs and xlist are the type arguments and corresponding type expressions, or nil.
var targs []Type
var xlist []syntax.Expr
assert(len(targs) == len(xlist))
}
- assert(tsig != nil || targs != nil)
-
// Check the number of type arguments (got) vs number of type parameters (want).
// Note that x is a function value, not a type expression, so we don't need to
// call under below.
case *Signature:
if t.tparams != nil {
if check.conf.EnableReverseTypeInference && T != nil {
- if _, ok := under(T).(*Signature); ok {
- check.funcInst(T, x.Pos(), x, nil)
+ if tsig, _ := under(T).(*Signature); tsig != nil {
+ check.funcInst(tsig, x.Pos(), x, nil)
return
}
}
case *syntax.IndexExpr:
if check.indexExpr(x, e) {
- check.funcInst(T, e.Pos(), x, e)
+ var tsig *Signature
+ if check.conf.EnableReverseTypeInference && T != nil {
+ tsig, _ = under(T).(*Signature)
+ }
+ check.funcInst(tsig, e.Pos(), x, e)
}
if x.mode == invalid {
goto Error
)
// funcInst type-checks a function instantiation and returns the result in x.
-// The incoming x must be an uninstantiated generic function. If ix != 0,
+// The incoming x must be an uninstantiated generic function. If ix != nil,
// it provides (some or all of) the type arguments (ix.Indices) for the
-// instantiation. If the target type T != nil and is a (non-generic) function
-// signature, the signature's parameter types are used to infer additional
-// missing type arguments of x, if any.
-// At least one of inst or T must be provided.
-func (check *Checker) funcInst(T Type, pos token.Pos, x *operand, ix *typeparams.IndexExpr) {
+// instantiation. If the target type tsig != nil, the signature's parameter
+// types are used to infer additional missing type arguments of x, if any.
+// At least one of tsig or ix must be provided.
+func (check *Checker) funcInst(tsig *Signature, pos token.Pos, x *operand, ix *typeparams.IndexExpr) {
+ assert(tsig != nil || ix != nil)
+
if !check.allowVersion(check.pkg, 1, 18) {
check.softErrorf(inNode(ix.Orig, ix.Lbrack), UnsupportedFeature, "function instantiation requires go1.18 or later")
}
- // tsig is the (assignment) target function signature, or nil.
- // TODO(gri) refactor and pass in tsig to funcInst instead
- var tsig *Signature
- if check.conf._EnableReverseTypeInference && T != nil {
- tsig, _ = under(T).(*Signature)
- }
-
// targs and xlist are the type arguments and corresponding type expressions, or nil.
var targs []Type
var xlist []ast.Expr
assert(len(targs) == len(xlist))
}
- assert(tsig != nil || targs != nil)
-
// Check the number of type arguments (got) vs number of type parameters (want).
// Note that x is a function value, not a type expression, so we don't need to
// call under below.
case *Signature:
if t.tparams != nil {
if check.conf._EnableReverseTypeInference && T != nil {
- if _, ok := under(T).(*Signature); ok {
- check.funcInst(T, x.Pos(), x, nil)
+ if tsig, _ := under(T).(*Signature); tsig != nil {
+ check.funcInst(tsig, x.Pos(), x, nil)
return
}
}
case *ast.IndexExpr, *ast.IndexListExpr:
ix := typeparams.UnpackIndexExpr(e)
if check.indexExpr(x, ix) {
- check.funcInst(T, e.Pos(), x, ix)
+ var tsig *Signature
+ if check.conf._EnableReverseTypeInference && T != nil {
+ tsig, _ = under(T).(*Signature)
+ }
+ check.funcInst(tsig, e.Pos(), x, ix)
}
if x.mode == invalid {
goto Error