]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types: minor fixes/cleanups around testing
authorRobert Griesemer <gri@golang.org>
Fri, 15 Jan 2021 22:37:35 +0000 (14:37 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 19 Jan 2021 21:02:48 +0000 (21:02 +0000)
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>
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/testdata/expr3.src

index 85bf0728c07e34516f1a43e7fd9344efc91fb7f4..b03b074b6d5ac8ce53994db4c9b2a748141a7e44 100644 (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 {
index b910d8d0eefb35b845c89b3f3e1121347a0ed105..9cce189140719cd2e86eb61e419408987560d5a5 100644 (file)
@@ -73,12 +73,8 @@ func isUntyped(typ Type) bool {
        return !isTyped(typ)
 }
 
-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 isOrdered(typ Type) bool   { return is(typ, IsOrdered) }
+func isConstType(typ Type) bool { return is(typ, IsConstType) }
 
 // IsInterface reports whether typ is an interface type.
 func IsInterface(typ Type) bool {
index 071c9bb367babc06ba1009a84e6581f9237eb040..6d0ac6cd94d54e3cd8895070e608ff417ca5edfe 100644 (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 {