Skip to content

Commit 43a27a7

Browse files
griesemergopherbot
authored andcommitted
go/types: export Info.FileVersions
For #62605. Change-Id: Icf1a8332e4b60d77607716b55893ea2f39ae2f10 Reviewed-on: https://go-review.googlesource.com/c/go/+/540056 Run-TryBot: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent cae35cd commit 43a27a7

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

api/next/62605.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg go/types, type Info struct, FileVersions map[*ast.File]string #62605

src/go/types/api.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ type Info struct {
286286
// appear in this list.
287287
InitOrder []*Initializer
288288

289-
// _FileVersions maps a file to the file's Go version string.
290-
// If the file doesn't specify a version and Config.GoVersion
291-
// is not given, the reported version is the empty string.
292-
// TODO(gri) should this be "go0.0" instead in that case?
293-
_FileVersions map[*ast.File]string
289+
// FileVersions maps a file to its Go version string.
290+
// If the file doesn't specify a version, the reported
291+
// string is Config.GoVersion.
292+
// Version strings begin with “go”, like “go1.21”, and
293+
// are suitable for use with the [go/version] package.
294+
FileVersions map[*ast.File]string
294295
}
295296

296297
func (info *Info) recordTypes() bool {

src/go/types/api_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,7 +2796,7 @@ func TestFileVersions(t *testing.T) {
27962796
conf := Config{GoVersion: test.moduleVersion}
27972797
versions := make(map[*ast.File]string)
27982798
var info Info
2799-
*_FileVersionsAddr(&info) = versions
2799+
info.FileVersions = versions
28002800
mustTypecheck(src, &conf, &info)
28012801

28022802
n := 0
@@ -2812,9 +2812,3 @@ func TestFileVersions(t *testing.T) {
28122812
}
28132813
}
28142814
}
2815-
2816-
// _FileVersionsAddr(conf) returns the address of the field info._FileVersions.
2817-
func _FileVersionsAddr(info *Info) *map[*ast.File]string {
2818-
v := reflect.Indirect(reflect.ValueOf(info))
2819-
return (*map[*ast.File]string)(v.FieldByName("_FileVersions").Addr().UnsafePointer())
2820-
}

src/go/types/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func (check *Checker) recordScope(node ast.Node, scope *Scope) {
634634
}
635635

636636
func (check *Checker) recordFileVersion(file *ast.File, version string) {
637-
if m := check._FileVersions; m != nil {
637+
if m := check.FileVersions; m != nil {
638638
m[file] = version
639639
}
640640
}

0 commit comments

Comments
 (0)