Skip to content

Commit

Permalink
[dev.typeparams] cmd/compile/internal/types: minor fixes/cleanups aro…
Browse files Browse the repository at this point in the history
…und 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>
  • Loading branch information
griesemer committed Jan 19, 2021
1 parent 502198c commit 3c0a39c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 11 additions & 3 deletions src/cmd/compile/internal/types2/check_test.go
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 2 additions & 6 deletions src/cmd/compile/internal/types2/predicates.go
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions src/cmd/compile/internal/types2/testdata/expr3.src
Expand Up @@ -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 {
Expand Down

0 comments on commit 3c0a39c

Please sign in to comment.