go/types: export Info.FileVersions

For #62605.

Change-Id: Icf1a8332e4b60d77607716b55893ea2f39ae2f10
Reviewed-on: https://go-review.googlesource.com/c/go/+/540056
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Robert Griesemer 2023-11-06 16:42:27 -08:00 committed by Gopher Robot
parent cae35cd258
commit 43a27a7e8c
4 changed files with 9 additions and 13 deletions

1
api/next/62605.txt Normal file
View file

@ -0,0 +1 @@
pkg go/types, type Info struct, FileVersions map[*ast.File]string #62605

View file

@ -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 {

View file

@ -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())
}

View file

@ -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
}
}