mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[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:
parent
502198c8dc
commit
3c0a39c964
3 changed files with 13 additions and 13 deletions
|
|
@ -47,12 +47,12 @@ var (
|
||||||
testFiles = flag.String("files", "", "space-separated list of test files")
|
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 files []*syntax.File
|
||||||
var errlist []error
|
var errlist []error
|
||||||
errh := func(err error) { errlist = append(errlist, err) }
|
errh := func(err error) { errlist = append(errlist, err) }
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
file, err := syntax.ParseFile(filename, errh, nil, syntax.AllowGenerics)
|
file, err := syntax.ParseFile(filename, errh, nil, mode)
|
||||||
if file == nil {
|
if file == nil {
|
||||||
t.Fatalf("%s: %s", filename, err)
|
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) {
|
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
|
// parse files and collect parser errors
|
||||||
files, errlist := parseFiles(t, sources)
|
files, errlist := parseFiles(t, sources, mode)
|
||||||
|
|
||||||
pkgName := "<no package>"
|
pkgName := "<no package>"
|
||||||
if len(files) > 0 {
|
if len(files) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -73,12 +73,8 @@ func isUntyped(typ Type) bool {
|
||||||
return !isTyped(typ)
|
return !isTyped(typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isOrdered(typ Type) bool { return is(typ, IsOrdered) }
|
func isOrdered(typ Type) bool { return is(typ, IsOrdered) }
|
||||||
|
func isConstType(typ Type) bool { return is(typ, IsConstType) }
|
||||||
func isConstType(typ Type) bool {
|
|
||||||
t := typ.Basic()
|
|
||||||
return t != nil && t.info&IsConstType != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsInterface reports whether typ is an interface type.
|
// IsInterface reports whether typ is an interface type.
|
||||||
func IsInterface(typ Type) bool {
|
func IsInterface(typ Type) bool {
|
||||||
|
|
|
||||||
|
|
@ -145,10 +145,6 @@ func indexes() {
|
||||||
ms = "foo" /* ERROR "cannot use .* in assignment" */ [1:2]
|
ms = "foo" /* ERROR "cannot use .* in assignment" */ [1:2]
|
||||||
ms = "foo" /* ERROR "cannot use .* in assignment" */ [i:j]
|
ms = "foo" /* ERROR "cannot use .* in assignment" */ [i:j]
|
||||||
_, _ = ss, ms
|
_, _ = 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 {
|
type T struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue