]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] go/types: export the Config.GoVersion field
authorRob Findley <rfindley@google.com>
Wed, 14 Jul 2021 18:19:36 +0000 (14:19 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 14 Jul 2021 19:22:19 +0000 (19:22 +0000)
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 <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/api.go
src/go/types/check.go
src/go/types/check_test.go
src/go/types/stdlib_test.go
src/go/types/types_test.go

index d3a95bc9910b8a7aa714701c67ab7894fcffb0d1..2bfbb8ce0cb9eb2f7e7e1cb3a9eea977fd2e4c16 100644 (file)
@@ -103,12 +103,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.
index e82056e7225db7f7ac3e76a8a27c080bf1e29253..aea319f4635fafb70e403ddc1e72e113d83d38c6 100644 (file)
@@ -180,9 +180,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{
index a5720f992e944d3090a86d9a8793ed9f8e2f311b..f0cfced97f223fe86f54a0270a9d38791bc8cf55 100644 (file)
@@ -244,7 +244,7 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man
        // typecheck and collect typechecker errors
        var conf Config
        conf.Sizes = sizes
-       SetGoVersion(&conf, goVersion)
+       conf.GoVersion = goVersion
 
        // special case for importC.src
        if len(filenames) == 1 {
index d86a77a110f7a7f9f68083e2c8d1545b6c6adfd9..3eb7519a91af06d2d27f8c19fdb1b4bb358e0ea9 100644 (file)
@@ -140,8 +140,7 @@ 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{Importer: stdLibImporter}
-                       SetGoVersion(&conf, goVersion)
+                       conf := Config{GoVersion: goVersion, Importer: stdLibImporter}
                        _, err = conf.Check(filename, fset, []*ast.File{file}, nil)
                }
 
index 7990414f4245beeeb0365e27b0d17beb6ce4d0f5..f2358c6e1988ca5898524058d48b67ea550d8303 100644 (file)
@@ -4,11 +4,5 @@
 
 package types
 
-// 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
-}
-
 // Debug is set if go/types is built with debug mode enabled.
 const Debug = debug