]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.typeparams] go/internal/typeparams: remove the Enabled guard
authorRob Findley <rfindley@google.com>
Fri, 16 Jul 2021 13:51:19 +0000 (09:51 -0400)
committerRobert Findley <rfindley@google.com>
Fri, 16 Jul 2021 23:08:28 +0000 (23:08 +0000)
Type parameters are now always enabled. Users should guard against type
checking generic code by using the types.Config.GoVersion field.

This cleans up some differences with types2.

Change-Id: Ie3e35a549e456a90a10d6a7e158ff58653cc1394
Reviewed-on: https://go-review.googlesource.com/c/go/+/335033
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/internal/typeparams/typeparams.go
src/go/parser/error_test.go
src/go/parser/parser.go
src/go/parser/resolver_test.go
src/go/parser/short_test.go
src/go/printer/printer_test.go
src/go/types/api_test.go
src/go/types/check_test.go
src/go/types/methodset_test.go
src/go/types/typexpr.go

index e102b77ef8422244d2699f59d040ac3e4e78f5f2..3191654d4f8607ef48b5c7c682336ee6ac50137c 100644 (file)
@@ -10,8 +10,6 @@ import (
        "go/token"
 )
 
-const Enabled = true
-
 func PackIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.Pos) ast.Expr {
        switch len(exprs) {
        case 0:
index e22ab124510941d6ed66e6f08050804680229e24..f35ba0b50173c9b8fcd8f2d8f7c52f20c503510e 100644 (file)
@@ -189,11 +189,7 @@ func TestErrors(t *testing.T) {
                t.Run(name, func(t *testing.T) {
                        if !d.IsDir() && !strings.HasPrefix(name, ".") && (strings.HasSuffix(name, ".src") || strings.HasSuffix(name, ".go2")) {
                                mode := DeclarationErrors | AllErrors
-                               if strings.HasSuffix(name, ".go2") {
-                                       if !typeparams.Enabled {
-                                               return
-                                       }
-                               } else {
+                               if !strings.HasSuffix(name, ".go2") {
                                        mode |= typeparams.DisallowParsing
                                }
                                checkErrors(t, filepath.Join(testdata, name), nil, mode, true)
index d1082591710dc88936f3ac0cf2458c6a2c50c28a..bdc2ad308c862084f43ed18c96a65f955d64978a 100644 (file)
@@ -77,7 +77,7 @@ func (p *parser) init(fset *token.FileSet, filename string, src []byte, mode Mod
 }
 
 func (p *parser) parseTypeParams() bool {
-       return typeparams.Enabled && p.mode&typeparams.DisallowParsing == 0
+       return p.mode&typeparams.DisallowParsing == 0
 }
 
 // ----------------------------------------------------------------------------
index 625c009c914d8342eebcbfbe2649f2ed786ac44d..0c06c592d5fea1e91785163ac186840f49d5c6ae 100644 (file)
@@ -41,11 +41,7 @@ func TestResolution(t *testing.T) {
                        path := filepath.Join(dir, fi.Name())
                        src := readFile(path) // panics on failure
                        var mode Mode
-                       if strings.HasSuffix(path, ".go2") {
-                               if !typeparams.Enabled {
-                                       t.Skip("type params are not enabled")
-                               }
-                       } else {
+                       if !strings.HasSuffix(path, ".go2") {
                                mode |= typeparams.DisallowParsing
                        }
                        file, err := ParseFile(fset, path, src, mode)
index 2467ccb4a7756f5496c024c80bc77388b7c47a80..bfc6f6714b9f59f0bb31079709f620a184aba0b4 100644 (file)
@@ -133,9 +133,6 @@ func TestValid(t *testing.T) {
                }
        })
        t.Run("tparams", func(t *testing.T) {
-               if !typeparams.Enabled {
-                       t.Skip("type params are not enabled")
-               }
                for _, src := range valids {
                        checkErrors(t, src, src, DeclarationErrors|AllErrors, false)
                }
@@ -268,9 +265,6 @@ func TestInvalid(t *testing.T) {
                }
        })
        t.Run("tparams", func(t *testing.T) {
-               if !typeparams.Enabled {
-                       t.Skip("type params are not enabled")
-               }
                for _, src := range invalids {
                        checkErrors(t, src, src, DeclarationErrors|AllErrors, true)
                }
index 20c97b8c08173065e23a2be9795b90beb904201f..ff8be4ae97a75ff5a1f1b645009ca13858188caa 100644 (file)
@@ -10,7 +10,6 @@ import (
        "flag"
        "fmt"
        "go/ast"
-       "go/internal/typeparams"
        "go/parser"
        "go/token"
        "io"
@@ -222,9 +221,6 @@ var data = []entry{
 func TestFiles(t *testing.T) {
        t.Parallel()
        for _, e := range data {
-               if !typeparams.Enabled && e.mode&allowTypeParams != 0 {
-                       continue
-               }
                source := filepath.Join(dataDir, e.source)
                golden := filepath.Join(dataDir, e.golden)
                mode := e.mode
index ef248781ccc13f239a12e2db5d22bdfe75d033f2..e6c209dda0d8e2bf074e051555901ec9e2964c41 100644 (file)
@@ -353,9 +353,6 @@ func TestTypesInfo(t *testing.T) {
        }
 
        for _, test := range tests {
-               if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
-                       continue
-               }
                info := Info{Types: make(map[ast.Expr]TypeAndValue)}
                var name string
                if strings.HasPrefix(test.src, broken) {
@@ -534,9 +531,6 @@ func TestDefsInfo(t *testing.T) {
        }
 
        for _, test := range tests {
-               if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
-                       continue
-               }
                info := Info{
                        Defs: make(map[*ast.Ident]Object),
                }
@@ -582,9 +576,6 @@ func TestUsesInfo(t *testing.T) {
        }
 
        for _, test := range tests {
-               if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
-                       continue
-               }
                info := Info{
                        Uses: make(map[*ast.Ident]Object),
                }
index f0cfced97f223fe86f54a0270a9d38791bc8cf55..692004facf1ab7173e26bb51671995ca4ee60916 100644 (file)
@@ -207,10 +207,8 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man
                t.Fatal("no source files")
        }
 
-       if strings.HasSuffix(filenames[0], ".go2") && !typeparams.Enabled {
-               t.Skip("type params are not enabled")
-       }
-       if strings.HasSuffix(filenames[0], ".go1") && typeparams.Enabled {
+       if strings.HasSuffix(filenames[0], ".go1") {
+               // TODO(rfindley): re-enable this test by using GoVersion.
                t.Skip("type params are enabled")
        }
 
@@ -356,14 +354,6 @@ func TestIndexRepresentability(t *testing.T) {
        testFiles(t, &StdSizes{4, 4}, []string{"index.go"}, [][]byte{[]byte(src)}, false, nil)
 }
 
-func TestIssue46453(t *testing.T) {
-       if typeparams.Enabled {
-               t.Skip("type params are enabled")
-       }
-       const src = "package p\ntype _ comparable // ERROR \"undeclared name: comparable\""
-       testFiles(t, nil, []string{"issue46453.go"}, [][]byte{[]byte(src)}, false, nil)
-}
-
 func TestCheck(t *testing.T)     { DefPredeclaredTestFuncs(); testDirFiles(t, "testdata/check", false) }
 func TestExamples(t *testing.T)  { testDirFiles(t, "testdata/examples", false) }
 func TestFixedbugs(t *testing.T) { testDirFiles(t, "testdata/fixedbugs", false) }
index 4a373fa2c4ff9846a46826a88a63b8c85b1522db..566356ad6dee553865160646dc656ed17d34a42f 100644 (file)
@@ -7,7 +7,6 @@ package types_test
 import (
        "testing"
 
-       "go/internal/typeparams"
        . "go/types"
 )
 
@@ -101,9 +100,7 @@ func TestNewMethodSet(t *testing.T) {
                check(src, methods, false)
        }
 
-       if typeparams.Enabled {
-               for src, methods := range genericTests {
-                       check(src, methods, true)
-               }
+       for src, methods := range genericTests {
+               check(src, methods, true)
        }
 }
index 64a1b37cef9cd52ac34ebd1f546428f847ab4b74..ea39473b510be6fb6fb625535cd03192e834a4bb 100644 (file)
@@ -263,11 +263,8 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
 
        case *ast.IndexExpr, *ast.MultiIndexExpr:
                ix := typeparams.UnpackIndexExpr(e)
-               if typeparams.Enabled {
-                       return check.instantiatedType(ix, def)
-               }
-               check.errorf(e0, _NotAType, "%s is not a type", e0)
-               check.use(ix.X)
+               // TODO(rfindley): type instantiation should require go1.18
+               return check.instantiatedType(ix, def)
 
        case *ast.ParenExpr:
                // Generic types must be instantiated before they can be used in any form.