mirror of
https://github.com/golang/go
synced 2024-11-26 06:17:57 -07: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"
|
"go/token"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Enabled = true
|
|
||||||
|
|
||||||
func PackIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.Pos) ast.Expr {
|
func PackIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.Pos) ast.Expr {
|
||||||
switch len(exprs) {
|
switch len(exprs) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -189,11 +189,7 @@ func TestErrors(t *testing.T) {
|
|||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
if !d.IsDir() && !strings.HasPrefix(name, ".") && (strings.HasSuffix(name, ".src") || strings.HasSuffix(name, ".go2")) {
|
if !d.IsDir() && !strings.HasPrefix(name, ".") && (strings.HasSuffix(name, ".src") || strings.HasSuffix(name, ".go2")) {
|
||||||
mode := DeclarationErrors | AllErrors
|
mode := DeclarationErrors | AllErrors
|
||||||
if strings.HasSuffix(name, ".go2") {
|
if !strings.HasSuffix(name, ".go2") {
|
||||||
if !typeparams.Enabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mode |= typeparams.DisallowParsing
|
mode |= typeparams.DisallowParsing
|
||||||
}
|
}
|
||||||
checkErrors(t, filepath.Join(testdata, name), nil, mode, true)
|
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 {
|
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())
|
path := filepath.Join(dir, fi.Name())
|
||||||
src := readFile(path) // panics on failure
|
src := readFile(path) // panics on failure
|
||||||
var mode Mode
|
var mode Mode
|
||||||
if strings.HasSuffix(path, ".go2") {
|
if !strings.HasSuffix(path, ".go2") {
|
||||||
if !typeparams.Enabled {
|
|
||||||
t.Skip("type params are not enabled")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mode |= typeparams.DisallowParsing
|
mode |= typeparams.DisallowParsing
|
||||||
}
|
}
|
||||||
file, err := ParseFile(fset, path, src, mode)
|
file, err := ParseFile(fset, path, src, mode)
|
||||||
|
@ -133,9 +133,6 @@ func TestValid(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("tparams", func(t *testing.T) {
|
t.Run("tparams", func(t *testing.T) {
|
||||||
if !typeparams.Enabled {
|
|
||||||
t.Skip("type params are not enabled")
|
|
||||||
}
|
|
||||||
for _, src := range valids {
|
for _, src := range valids {
|
||||||
checkErrors(t, src, src, DeclarationErrors|AllErrors, false)
|
checkErrors(t, src, src, DeclarationErrors|AllErrors, false)
|
||||||
}
|
}
|
||||||
@ -268,9 +265,6 @@ func TestInvalid(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.Run("tparams", func(t *testing.T) {
|
t.Run("tparams", func(t *testing.T) {
|
||||||
if !typeparams.Enabled {
|
|
||||||
t.Skip("type params are not enabled")
|
|
||||||
}
|
|
||||||
for _, src := range invalids {
|
for _, src := range invalids {
|
||||||
checkErrors(t, src, src, DeclarationErrors|AllErrors, true)
|
checkErrors(t, src, src, DeclarationErrors|AllErrors, true)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/internal/typeparams"
|
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io"
|
"io"
|
||||||
@ -222,9 +221,6 @@ var data = []entry{
|
|||||||
func TestFiles(t *testing.T) {
|
func TestFiles(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
for _, e := range data {
|
for _, e := range data {
|
||||||
if !typeparams.Enabled && e.mode&allowTypeParams != 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
source := filepath.Join(dataDir, e.source)
|
source := filepath.Join(dataDir, e.source)
|
||||||
golden := filepath.Join(dataDir, e.golden)
|
golden := filepath.Join(dataDir, e.golden)
|
||||||
mode := e.mode
|
mode := e.mode
|
||||||
|
@ -353,9 +353,6 @@ func TestTypesInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
info := Info{Types: make(map[ast.Expr]TypeAndValue)}
|
info := Info{Types: make(map[ast.Expr]TypeAndValue)}
|
||||||
var name string
|
var name string
|
||||||
if strings.HasPrefix(test.src, broken) {
|
if strings.HasPrefix(test.src, broken) {
|
||||||
@ -534,9 +531,6 @@ func TestDefsInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
info := Info{
|
info := Info{
|
||||||
Defs: make(map[*ast.Ident]Object),
|
Defs: make(map[*ast.Ident]Object),
|
||||||
}
|
}
|
||||||
@ -582,9 +576,6 @@ func TestUsesInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
info := Info{
|
info := Info{
|
||||||
Uses: make(map[*ast.Ident]Object),
|
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")
|
t.Fatal("no source files")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(filenames[0], ".go2") && !typeparams.Enabled {
|
if strings.HasSuffix(filenames[0], ".go1") {
|
||||||
t.Skip("type params are not enabled")
|
// TODO(rfindley): re-enable this test by using GoVersion.
|
||||||
}
|
|
||||||
if strings.HasSuffix(filenames[0], ".go1") && typeparams.Enabled {
|
|
||||||
t.Skip("type params are enabled")
|
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)
|
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 TestCheck(t *testing.T) { DefPredeclaredTestFuncs(); testDirFiles(t, "testdata/check", false) }
|
||||||
func TestExamples(t *testing.T) { testDirFiles(t, "testdata/examples", false) }
|
func TestExamples(t *testing.T) { testDirFiles(t, "testdata/examples", false) }
|
||||||
func TestFixedbugs(t *testing.T) { testDirFiles(t, "testdata/fixedbugs", false) }
|
func TestFixedbugs(t *testing.T) { testDirFiles(t, "testdata/fixedbugs", false) }
|
||||||
|
@ -7,7 +7,6 @@ package types_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go/internal/typeparams"
|
|
||||||
. "go/types"
|
. "go/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -101,9 +100,7 @@ func TestNewMethodSet(t *testing.T) {
|
|||||||
check(src, methods, false)
|
check(src, methods, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if typeparams.Enabled {
|
for src, methods := range genericTests {
|
||||||
for src, methods := range genericTests {
|
check(src, methods, true)
|
||||||
check(src, methods, true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,11 +263,8 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
|
|||||||
|
|
||||||
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
case *ast.IndexExpr, *ast.MultiIndexExpr:
|
||||||
ix := typeparams.UnpackIndexExpr(e)
|
ix := typeparams.UnpackIndexExpr(e)
|
||||||
if typeparams.Enabled {
|
// TODO(rfindley): type instantiation should require go1.18
|
||||||
return check.instantiatedType(ix, def)
|
return check.instantiatedType(ix, def)
|
||||||
}
|
|
||||||
check.errorf(e0, _NotAType, "%s is not a type", e0)
|
|
||||||
check.use(ix.X)
|
|
||||||
|
|
||||||
case *ast.ParenExpr:
|
case *ast.ParenExpr:
|
||||||
// Generic types must be instantiated before they can be used in any form.
|
// Generic types must be instantiated before they can be used in any form.
|
||||||
|
Loading…
Reference in New Issue
Block a user