mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
[dev.typeparams] go/internal/typeparams: remove the Enabled guard
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>
This commit is contained in:
parent
726ffce659
commit
5f50a6442e
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue