// type-checked.
IgnoreFuncBodies bool
- // If AcceptMethodTypeParams is set, methods may have type parameters.
- AcceptMethodTypeParams 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).
t.Fatalf("%s: unable to parse: %s", path, err)
}
conf := Config{
- AcceptMethodTypeParams: true,
- Error: func(err error) {},
- Importer: defaultImporter(),
+ Error: func(err error) {},
+ Importer: defaultImporter(),
}
pkg, err := conf.Check(f.PkgName.Value, []*syntax.File{f}, info)
return pkg.Name(), err
//
const forceStrict = false
-// If methodTypeParamsOk is set, type parameters are
-// permitted in method declarations (in interfaces, too).
-// Generalization and experimental feature.
-const methodTypeParamsOk = true
-
// exprInfo stores information about an untyped expression.
type exprInfo struct {
isLhs bool // expression is lhs operand of a shift with delayed type-check
// typecheck and collect typechecker errors
var conf Config
conf.GoVersion = goVersion
- conf.AcceptMethodTypeParams = true
// special case for importC.src
if len(filenames) == 1 && strings.HasSuffix(filenames[0], "importC.src") {
conf.FakeImportC = true
} else {
// method
// d.Recv != nil
- if !methodTypeParamsOk && len(d.TParamList) != 0 {
+ if !acceptMethodTypeParams && len(d.TParamList) != 0 {
//check.error(d.TParamList.Pos(), invalidAST + "method must have no type parameters")
check.error(d, invalidAST+"method must have no type parameters")
}
--- /dev/null
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package types2
+
+func init() {
+ acceptMethodTypeParams = true
+}
"strings"
)
+// Disabled by default, but enabled when running tests (via types_test.go).
+var acceptMethodTypeParams bool
+
// ident type-checks identifier e and initializes x with the value or type of e.
// If an error occurred, x.mode is set to invalid.
// For the meaning of def, see Checker.definedType, below.
// Always type-check method type parameters but complain if they are not enabled.
// (A separate check is needed when type-checking interface method signatures because
// they don't have a receiver specification.)
- if recvPar != nil && !check.conf.AcceptMethodTypeParams {
+ if recvPar != nil && !acceptMethodTypeParams {
check.error(ftyp, "methods cannot have type parameters")
}
}
// Always type-check method type parameters but complain if they are not enabled.
// (This extra check is needed here because interface method signatures don't have
// a receiver specification.)
- if sig.tparams != nil && !check.conf.AcceptMethodTypeParams {
+ if sig.tparams != nil && !acceptMethodTypeParams {
check.error(f.Type, "methods cannot have type parameters")
}