]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: remove Config.AcceptMethodTypeParams flag
authorRobert Griesemer <gri@golang.org>
Mon, 5 Apr 2021 21:30:03 +0000 (14:30 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 7 Apr 2021 05:19:22 +0000 (05:19 +0000)
Type parameters for methods are not part of the accepted language,
but maintaining the code for type-checking them ensures regularity
of the type checker implementation. For now, keep the flag internally,
disabled by default. The flag is set when running tests.

Change-Id: Ic99934bd00bd2608dc1178e4131f46dd1507f0f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/307214
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/resolver.go
src/cmd/compile/internal/types2/types_test.go [new file with mode: 0644]
src/cmd/compile/internal/types2/typexpr.go

index 63008711bf90c9daa2dc3bbedba97c0708583221..2939dcc0bdf27356ae1c5a99abfd44c836004060 100644 (file)
@@ -107,9 +107,6 @@ type Config struct {
        // 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).
index b5990e5d46c52ede0c0f4d498a6029ba8762e0cc..9d31fef69b34bf272e6e849143f0e9bde0e9c0be 100644 (file)
@@ -65,9 +65,8 @@ func mayTypecheck(t *testing.T, path, source string, info *Info) (string, error)
                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
index 7d499eb13dbf1b420c7da81c4b0192156c4015be..2edcefd4c8748807f17959a83cf6a8d47082aea3 100644 (file)
@@ -31,11 +31,6 @@ const debug = false // leave on during development
 //
 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
index a6baa71b2a90b3a116cb85ba3e02e6b3ddeab10a..2418c29a2fbcaaeeefdff4e70507184f91affa85 100644 (file)
@@ -128,7 +128,6 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
        // 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
index 35bb72ee55c59a459271d5b76f2a85e230874f15..86eeb72b21c0b62f8abc3f5f35900bff140cb0e2 100644 (file)
@@ -426,7 +426,7 @@ func (check *Checker) collectObjects() {
                                } 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")
                                        }
diff --git a/src/cmd/compile/internal/types2/types_test.go b/src/cmd/compile/internal/types2/types_test.go
new file mode 100644 (file)
index 0000000..11dca0b
--- /dev/null
@@ -0,0 +1,9 @@
+// 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
+}
index ce2fd7797b957648d6b0db6a20ee92219a0899f0..e7d24949a47981dec77c95c3caa1dc11390ed6c8 100644 (file)
@@ -15,6 +15,9 @@ import (
        "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.
@@ -336,7 +339,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *syntax.Field, tparams []
                // 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")
                }
        }
@@ -848,7 +851,7 @@ func (check *Checker) interfaceType(ityp *Interface, iface *syntax.InterfaceType
                        // 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")
                        }