aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-05-28 11:58:05 -0400
committerRobert Findley <rfindley@google.com>2021-05-30 02:37:38 +0000
commit1607c2817241bd141af9331a3e6c3148e5cd5d8b (patch)
treed7098a39fb8c729c392c1c8954612a7d803524b8
parent79bda650410c8617f0ae20dc552c6d5b8f8dcfc8 (diff)
downloadgo-1607c2817241bd141af9331a3e6c3148e5cd5d8b.tar.gz
go-1607c2817241bd141af9331a3e6c3148e5cd5d8b.zip
go/types: unexport the GoVersion configuration option for Go 1.17
The GoVersion field was added to types.Config as part of the work on type parameters. Specifically, it was added to be consistent with cmd/compile/internal/types2, which requires such an option. This configuration option is useful, but is also non-trivial and did not go through the proposal process. Unexport it for Go 1.17; we can create a proposal to export it for Go 1.18. Fixes #46296 Change-Id: Id82d8a7096887dcfc404c4d6d8da9c761b316609 Reviewed-on: https://go-review.googlesource.com/c/go/+/323430 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
-rw-r--r--src/go/types/api.go4
-rw-r--r--src/go/types/check.go4
-rw-r--r--src/go/types/check_test.go2
-rw-r--r--src/go/types/stdlib_test.go3
-rw-r--r--src/go/types/types_test.go6
5 files changed, 13 insertions, 6 deletions
diff --git a/src/go/types/api.go b/src/go/types/api.go
index ed62a785d6..8c0d9d22bf 100644
--- a/src/go/types/api.go
+++ b/src/go/types/api.go
@@ -101,12 +101,12 @@ type ImporterFrom interface {
// A Config specifies the configuration for type checking.
// The zero value for Config is a ready-to-use default configuration.
type Config struct {
- // GoVersion describes the accepted Go language version. The string
+ // goVersion describes the accepted Go language version. The string
// must follow the format "go%d.%d" (e.g. "go1.12") or it must be
// empty; an empty string indicates the latest language version.
// If the format is invalid, invoking the type checker will cause a
// panic.
- GoVersion string
+ goVersion string
// If IgnoreFuncBodies is set, function bodies are not
// type-checked.
diff --git a/src/go/types/check.go b/src/go/types/check.go
index 25ea4906be..a923c3c612 100644
--- a/src/go/types/check.go
+++ b/src/go/types/check.go
@@ -179,9 +179,9 @@ func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Ch
info = new(Info)
}
- version, err := parseGoVersion(conf.GoVersion)
+ version, err := parseGoVersion(conf.goVersion)
if err != nil {
- panic(fmt.Sprintf("invalid Go version %q (%v)", conf.GoVersion, err))
+ panic(fmt.Sprintf("invalid Go version %q (%v)", conf.goVersion, err))
}
return &Checker{
diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go
index c5dc93eade..9c71277264 100644
--- a/src/go/types/check_test.go
+++ b/src/go/types/check_test.go
@@ -240,7 +240,7 @@ func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string,
// typecheck and collect typechecker errors
var conf Config
conf.Sizes = sizes
- conf.GoVersion = goVersion
+ SetGoVersion(&conf, goVersion)
// special case for importC.src
if len(filenames) == 1 {
diff --git a/src/go/types/stdlib_test.go b/src/go/types/stdlib_test.go
index 3dea8dcf1e..503d0a6f44 100644
--- a/src/go/types/stdlib_test.go
+++ b/src/go/types/stdlib_test.go
@@ -134,7 +134,8 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
// parse and type-check file
file, err := parser.ParseFile(fset, filename, nil, 0)
if err == nil {
- conf := Config{GoVersion: goVersion, Importer: stdLibImporter}
+ conf := Config{Importer: stdLibImporter}
+ SetGoVersion(&conf, goVersion)
_, err = conf.Check(filename, fset, []*ast.File{file}, nil)
}
diff --git a/src/go/types/types_test.go b/src/go/types/types_test.go
index fd9462c4a2..25cd996628 100644
--- a/src/go/types/types_test.go
+++ b/src/go/types/types_test.go
@@ -11,3 +11,9 @@ import "sync/atomic"
// for tests where we may want to have a consistent
// numbering for each individual test case.
func ResetId() { atomic.StoreUint32(&lastId, 0) }
+
+// SetGoVersion sets the unexported goVersion field on config, so that tests
+// which assert on behavior for older Go versions can set it.
+func SetGoVersion(config *Config, goVersion string) {
+ config.goVersion = goVersion
+}