[dev.typeparams] cmd/compile/internal/types: minor fixes/cleanups around testing

Also, implemented isConstType predicate in terms of "is" predicate.

Change-Id: Ib3b311f52196dba974802348bc6d63307530d915
Reviewed-on: https://go-review.googlesource.com/c/go/+/284217
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2021-01-15 14:37:35 -08:00
parent 502198c8dc
commit 3c0a39c964
3 changed files with 13 additions and 13 deletions

View file

@ -47,12 +47,12 @@ var (
testFiles = flag.String("files", "", "space-separated list of test files")
)
func parseFiles(t *testing.T, filenames []string) ([]*syntax.File, []error) {
func parseFiles(t *testing.T, filenames []string, mode syntax.Mode) ([]*syntax.File, []error) {
var files []*syntax.File
var errlist []error
errh := func(err error) { errlist = append(errlist, err) }
for _, filename := range filenames {
file, err := syntax.ParseFile(filename, errh, nil, syntax.AllowGenerics)
file, err := syntax.ParseFile(filename, errh, nil, mode)
if file == nil {
t.Fatalf("%s: %s", filename, err)
}
@ -84,8 +84,16 @@ func delta(x, y uint) uint {
}
func checkFiles(t *testing.T, sources []string, colDelta uint, trace bool) {
if len(sources) == 0 {
t.Fatal("no source files")
}
var mode syntax.Mode
if strings.HasSuffix(sources[0], ".go2") {
mode |= syntax.AllowGenerics
}
// parse files and collect parser errors
files, errlist := parseFiles(t, sources)
files, errlist := parseFiles(t, sources, mode)
pkgName := "<no package>"
if len(files) > 0 {

View file

@ -74,11 +74,7 @@ func isUntyped(typ Type) bool {
}
func isOrdered(typ Type) bool { return is(typ, IsOrdered) }
func isConstType(typ Type) bool {
t := typ.Basic()
return t != nil && t.info&IsConstType != 0
}
func isConstType(typ Type) bool { return is(typ, IsConstType) }
// IsInterface reports whether typ is an interface type.
func IsInterface(typ Type) bool {

View file

@ -145,10 +145,6 @@ func indexes() {
ms = "foo" /* ERROR "cannot use .* in assignment" */ [1:2]
ms = "foo" /* ERROR "cannot use .* in assignment" */ [i:j]
_, _ = ss, ms
// With type parameters, index expressions may have multiple indices.
_ = a[i, j /* ERROR "more than one index" */ ]
_ = a[i, j /* ERROR "more than one index" */ , j]
}
type T struct {