mirror of
https://github.com/golang/go.git
synced 2025-05-07 00:23:03 +00:00
go/types, types2: adjust Check.funcInst signature
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>
This commit is contained in:
parent
f46ea60f2b
commit
9c75c4b6d7
@ -15,24 +15,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// funcInst type-checks a function instantiation and returns the result in x.
|
// 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
|
// 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
|
// instantiation. If the target type tsig != nil, the signature's parameter
|
||||||
// signature, the signature's parameter types are used to infer additional
|
// types are used to infer additional missing type arguments of x, if any.
|
||||||
// missing type arguments of x, if any.
|
// At least one of tsig or inst must be provided.
|
||||||
// At least one of inst or T must be provided.
|
func (check *Checker) funcInst(tsig *Signature, pos syntax.Pos, x *operand, inst *syntax.IndexExpr) {
|
||||||
func (check *Checker) funcInst(T Type, pos syntax.Pos, x *operand, inst *syntax.IndexExpr) {
|
assert(tsig != nil || inst != nil)
|
||||||
|
|
||||||
if !check.allowVersion(check.pkg, 1, 18) {
|
if !check.allowVersion(check.pkg, 1, 18) {
|
||||||
check.versionErrorf(inst.Pos(), "go1.18", "function instantiation")
|
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.
|
// targs and xlist are the type arguments and corresponding type expressions, or nil.
|
||||||
var targs []Type
|
var targs []Type
|
||||||
var xlist []syntax.Expr
|
var xlist []syntax.Expr
|
||||||
@ -47,8 +41,6 @@ func (check *Checker) funcInst(T Type, pos syntax.Pos, x *operand, inst *syntax.
|
|||||||
assert(len(targs) == len(xlist))
|
assert(len(targs) == len(xlist))
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(tsig != nil || targs != nil)
|
|
||||||
|
|
||||||
// Check the number of type arguments (got) vs number of type parameters (want).
|
// 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
|
// Note that x is a function value, not a type expression, so we don't need to
|
||||||
// call under below.
|
// call under below.
|
||||||
|
@ -1293,8 +1293,8 @@ func (check *Checker) nonGeneric(T Type, x *operand) {
|
|||||||
case *Signature:
|
case *Signature:
|
||||||
if t.tparams != nil {
|
if t.tparams != nil {
|
||||||
if check.conf.EnableReverseTypeInference && T != nil {
|
if check.conf.EnableReverseTypeInference && T != nil {
|
||||||
if _, ok := under(T).(*Signature); ok {
|
if tsig, _ := under(T).(*Signature); tsig != nil {
|
||||||
check.funcInst(T, x.Pos(), x, nil)
|
check.funcInst(tsig, x.Pos(), x, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1617,7 +1617,11 @@ func (check *Checker) exprInternal(T Type, x *operand, e syntax.Expr, hint Type)
|
|||||||
|
|
||||||
case *syntax.IndexExpr:
|
case *syntax.IndexExpr:
|
||||||
if check.indexExpr(x, e) {
|
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 {
|
if x.mode == invalid {
|
||||||
goto Error
|
goto Error
|
||||||
|
@ -17,24 +17,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// funcInst type-checks a function instantiation and returns the result in x.
|
// 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
|
// 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
|
// instantiation. If the target type tsig != nil, the signature's parameter
|
||||||
// signature, the signature's parameter types are used to infer additional
|
// types are used to infer additional missing type arguments of x, if any.
|
||||||
// missing type arguments of x, if any.
|
// At least one of tsig or ix must be provided.
|
||||||
// At least one of inst or T must be provided.
|
func (check *Checker) funcInst(tsig *Signature, pos token.Pos, x *operand, ix *typeparams.IndexExpr) {
|
||||||
func (check *Checker) funcInst(T Type, pos token.Pos, x *operand, ix *typeparams.IndexExpr) {
|
assert(tsig != nil || ix != nil)
|
||||||
|
|
||||||
if !check.allowVersion(check.pkg, 1, 18) {
|
if !check.allowVersion(check.pkg, 1, 18) {
|
||||||
check.softErrorf(inNode(ix.Orig, ix.Lbrack), UnsupportedFeature, "function instantiation requires go1.18 or later")
|
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.
|
// targs and xlist are the type arguments and corresponding type expressions, or nil.
|
||||||
var targs []Type
|
var targs []Type
|
||||||
var xlist []ast.Expr
|
var xlist []ast.Expr
|
||||||
@ -49,8 +43,6 @@ func (check *Checker) funcInst(T Type, pos token.Pos, x *operand, ix *typeparams
|
|||||||
assert(len(targs) == len(xlist))
|
assert(len(targs) == len(xlist))
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(tsig != nil || targs != nil)
|
|
||||||
|
|
||||||
// Check the number of type arguments (got) vs number of type parameters (want).
|
// 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
|
// Note that x is a function value, not a type expression, so we don't need to
|
||||||
// call under below.
|
// call under below.
|
||||||
|
@ -1278,8 +1278,8 @@ func (check *Checker) nonGeneric(T Type, x *operand) {
|
|||||||
case *Signature:
|
case *Signature:
|
||||||
if t.tparams != nil {
|
if t.tparams != nil {
|
||||||
if check.conf._EnableReverseTypeInference && T != nil {
|
if check.conf._EnableReverseTypeInference && T != nil {
|
||||||
if _, ok := under(T).(*Signature); ok {
|
if tsig, _ := under(T).(*Signature); tsig != nil {
|
||||||
check.funcInst(T, x.Pos(), x, nil)
|
check.funcInst(tsig, x.Pos(), x, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1600,7 +1600,11 @@ func (check *Checker) exprInternal(T Type, x *operand, e ast.Expr, hint Type) ex
|
|||||||
case *ast.IndexExpr, *ast.IndexListExpr:
|
case *ast.IndexExpr, *ast.IndexListExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(e)
|
ix := typeparams.UnpackIndexExpr(e)
|
||||||
if check.indexExpr(x, ix) {
|
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 {
|
if x.mode == invalid {
|
||||||
goto Error
|
goto Error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user