// If AcceptMethodTypeParams is set, methods may have type parameters.
AcceptMethodTypeParams bool
- // If InferFromConstraints is set, constraint type inference is used
- // if some function type arguments are missing.
- InferFromConstraints bool
-
// If FakeImportC is set, `import "C"` (for packages requiring Cgo)
// declares an empty "C" package and errors are omitted for qualified
// identifiers referring to package C (which won't find an object).
// check number of type arguments (got) vs number of type parameters (want)
sig := x.typ.(*Signature)
got, want := len(targs), len(sig.tparams)
- if !check.conf.InferFromConstraints && got != want || got > want {
+ if !useConstraintTypeInference && got != want || got > want {
check.errorf(xlist[got-1], "got %d type arguments but want %d", got, want)
x.mode = invalid
x.expr = inst
"cmd/compile/internal/syntax"
)
+const useConstraintTypeInference = true
+
// infer attempts to infer the complete set of type arguments for generic function instantiation/call
// based on the given type parameters tparams, type arguments targs, function parameters params, and
// function arguments args, if any. There must be at least one type parameter, no more type arguments
// and types inferred via constraint type inference take precedence over types
// inferred from function arguments.
// If we have type arguments, see how far we get with constraint type inference.
- if len(targs) > 0 && check.conf.InferFromConstraints {
+ if len(targs) > 0 && useConstraintTypeInference {
var index int
targs, index = check.inferB(tparams, targs, report)
if targs == nil || index < 0 {
// See how far we get with constraint type inference.
// Note that even if we don't have any type arguments, constraint type inference
// may produce results for constraints that explicitly specify a type.
- if check.conf.InferFromConstraints {
+ if useConstraintTypeInference {
targs, index = check.inferB(tparams, targs, report)
if targs == nil || index < 0 {
return targs
}
// Again, follow up with constraint type inference.
- if check.conf.InferFromConstraints {
+ if useConstraintTypeInference {
targs, index = check.inferB(tparams, targs, report)
if targs == nil || index < 0 {
return targs