]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/check.go
go/types: export Info.FileVersions
[gostls13.git] / src / go / types / check.go
index c714754fef68a57c44ec2dba7e76ad991ecc9fa6..89b8ee07a25d9f71049a7be0281a3cdce61e56c7 100644 (file)
@@ -90,7 +90,7 @@ type actionDesc struct {
 }
 
 // A Checker maintains the state of the type checker.
-// It must be created with NewChecker.
+// It must be created with [NewChecker].
 type Checker struct {
        // package information
        // (initialized by NewChecker, valid for the life-time of checker)
@@ -221,8 +221,8 @@ func (check *Checker) needsCleanup(c cleaner) {
        check.cleaners = append(check.cleaners, c)
 }
 
-// NewChecker returns a new Checker instance for a given package.
-// Package files may be added incrementally via checker.Files.
+// NewChecker returns a new [Checker] instance for a given package.
+// [Package] files may be added incrementally via checker.Files.
 func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker {
        // make sure we have a configuration
        if conf == nil {
@@ -287,11 +287,10 @@ func (check *Checker) initFiles(files []*ast.File) {
                }
        }
 
+       // collect file versions
        for _, file := range check.files {
-               fbase := file.FileStart
-               check.recordFileVersion(fbase, check.version) // record package version (possibly zero version)
-               v, _ := parseGoVersion(file.GoVersion)
-               if v.major > 0 {
+               check.recordFileVersion(file, check.conf.GoVersion)
+               if v, _ := parseGoVersion(file.GoVersion); v.major > 0 {
                        if v.equal(check.version) {
                                continue
                        }
@@ -314,18 +313,12 @@ func (check *Checker) initFiles(files []*ast.File) {
                        if check.posVers == nil {
                                check.posVers = make(map[token.Pos]version)
                        }
-                       check.posVers[fbase] = v
-                       check.recordFileVersion(fbase, v) // overwrite package version
+                       check.posVers[file.FileStart] = v
+                       check.recordFileVersion(file, file.GoVersion) // overwrite package version
                }
        }
 }
 
-// A posVers records that the file starting at pos declares the Go version vers.
-type posVers struct {
-       pos  token.Pos
-       vers version
-}
-
 // A bailout panic is used for early termination.
 type bailout struct{}
 
@@ -640,8 +633,8 @@ func (check *Checker) recordScope(node ast.Node, scope *Scope) {
        }
 }
 
-func (check *Checker) recordFileVersion(pos token.Pos, v version) {
-       if m := check._FileVersions; m != nil {
-               m[pos] = _Version{v.major, v.minor}
+func (check *Checker) recordFileVersion(file *ast.File, version string) {
+       if m := check.FileVersions; m != nil {
+               m[file] = version
        }
 }