"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:
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)
}
func (p *parser) parseTypeParams() bool {
- return typeparams.Enabled && p.mode&typeparams.DisallowParsing == 0
+ return p.mode&typeparams.DisallowParsing == 0
}
// ----------------------------------------------------------------------------
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)
}
})
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)
}
}
})
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)
}
"flag"
"fmt"
"go/ast"
- "go/internal/typeparams"
"go/parser"
"go/token"
"io"
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
}
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) {
}
for _, test := range tests {
- if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
- continue
- }
info := Info{
Defs: make(map[*ast.Ident]Object),
}
}
for _, test := range tests {
- if strings.HasPrefix(test.src, genericPkg) && !typeparams.Enabled {
- continue
- }
info := Info{
Uses: make(map[*ast.Ident]Object),
}
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")
}
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) }
import (
"testing"
- "go/internal/typeparams"
. "go/types"
)
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)
}
}
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.