Skip to content

Commit 2b10d7f

Browse files
committed
[dev.typeparams] go/types: export the Config.GoVersion field
Export the types.Config.GoVersion field, so that users can specify a language compatibility version for go/types to enforce. Updates #46648 Change-Id: I9e00122925faf0006cfb08c3f2d022619d5d54d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/334533 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 5517053 commit 2b10d7f

File tree

5 files changed

+6
-13
lines changed

5 files changed

+6
-13
lines changed

src/go/types/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ type ImporterFrom interface {
103103
// A Config specifies the configuration for type checking.
104104
// The zero value for Config is a ready-to-use default configuration.
105105
type Config struct {
106-
// goVersion describes the accepted Go language version. The string
106+
// GoVersion describes the accepted Go language version. The string
107107
// must follow the format "go%d.%d" (e.g. "go1.12") or it must be
108108
// empty; an empty string indicates the latest language version.
109109
// If the format is invalid, invoking the type checker will cause a
110110
// panic.
111-
goVersion string
111+
GoVersion string
112112

113113
// If IgnoreFuncBodies is set, function bodies are not
114114
// type-checked.

src/go/types/check.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Ch
180180
info = new(Info)
181181
}
182182

183-
version, err := parseGoVersion(conf.goVersion)
183+
version, err := parseGoVersion(conf.GoVersion)
184184
if err != nil {
185-
panic(fmt.Sprintf("invalid Go version %q (%v)", conf.goVersion, err))
185+
panic(fmt.Sprintf("invalid Go version %q (%v)", conf.GoVersion, err))
186186
}
187187

188188
return &Checker{

src/go/types/check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man
244244
// typecheck and collect typechecker errors
245245
var conf Config
246246
conf.Sizes = sizes
247-
SetGoVersion(&conf, goVersion)
247+
conf.GoVersion = goVersion
248248

249249
// special case for importC.src
250250
if len(filenames) == 1 {

src/go/types/stdlib_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
140140
// parse and type-check file
141141
file, err := parser.ParseFile(fset, filename, nil, 0)
142142
if err == nil {
143-
conf := Config{Importer: stdLibImporter}
144-
SetGoVersion(&conf, goVersion)
143+
conf := Config{GoVersion: goVersion, Importer: stdLibImporter}
145144
_, err = conf.Check(filename, fset, []*ast.File{file}, nil)
146145
}
147146

src/go/types/types_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@
44

55
package types
66

7-
// SetGoVersion sets the unexported goVersion field on config, so that tests
8-
// which assert on behavior for older Go versions can set it.
9-
func SetGoVersion(config *Config, goVersion string) {
10-
config.goVersion = goVersion
11-
}
12-
137
// Debug is set if go/types is built with debug mode enabled.
148
const Debug = debug

0 commit comments

Comments
 (0)