From: Robert Griesemer Date: Tue, 7 Nov 2023 00:42:27 +0000 (-0800) Subject: go/types: export Info.FileVersions X-Git-Tag: go1.22rc1~405 X-Git-Url: http://www.git.cypherpunks.ru/?p=gostls13.git;a=commitdiff_plain;h=43a27a7e8cbde4270e3f2b4e6e1538b28882c2d0 go/types: export Info.FileVersions For #62605. Change-Id: Icf1a8332e4b60d77607716b55893ea2f39ae2f10 Reviewed-on: https://go-review.googlesource.com/c/go/+/540056 Run-TryBot: Robert Griesemer Auto-Submit: Robert Griesemer Reviewed-by: Alan Donovan Reviewed-by: Robert Griesemer TryBot-Result: Gopher Robot --- diff --git a/api/next/62605.txt b/api/next/62605.txt new file mode 100644 index 0000000000..1b0e533d02 --- /dev/null +++ b/api/next/62605.txt @@ -0,0 +1 @@ +pkg go/types, type Info struct, FileVersions map[*ast.File]string #62605 diff --git a/src/go/types/api.go b/src/go/types/api.go index 33633ea83c..81a98f7e66 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -286,11 +286,12 @@ type Info struct { // appear in this list. InitOrder []*Initializer - // _FileVersions maps a file to the file's Go version string. - // If the file doesn't specify a version and Config.GoVersion - // is not given, the reported version is the empty string. - // TODO(gri) should this be "go0.0" instead in that case? - _FileVersions map[*ast.File]string + // FileVersions maps a file to its Go version string. + // If the file doesn't specify a version, the reported + // string is Config.GoVersion. + // Version strings begin with “go”, like “go1.21”, and + // are suitable for use with the [go/version] package. + FileVersions map[*ast.File]string } func (info *Info) recordTypes() bool { diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index f3719ddf6d..0769890101 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -2796,7 +2796,7 @@ func TestFileVersions(t *testing.T) { conf := Config{GoVersion: test.moduleVersion} versions := make(map[*ast.File]string) var info Info - *_FileVersionsAddr(&info) = versions + info.FileVersions = versions mustTypecheck(src, &conf, &info) n := 0 @@ -2812,9 +2812,3 @@ func TestFileVersions(t *testing.T) { } } } - -// _FileVersionsAddr(conf) returns the address of the field info._FileVersions. -func _FileVersionsAddr(info *Info) *map[*ast.File]string { - v := reflect.Indirect(reflect.ValueOf(info)) - return (*map[*ast.File]string)(v.FieldByName("_FileVersions").Addr().UnsafePointer()) -} diff --git a/src/go/types/check.go b/src/go/types/check.go index 99696de496..89b8ee07a2 100644 --- a/src/go/types/check.go +++ b/src/go/types/check.go @@ -634,7 +634,7 @@ func (check *Checker) recordScope(node ast.Node, scope *Scope) { } func (check *Checker) recordFileVersion(file *ast.File, version string) { - if m := check._FileVersions; m != nil { + if m := check.FileVersions; m != nil { m[file] = version } }