]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/ast: add File.GoVersion
authorRuss Cox <rsc@golang.org>
Mon, 13 Mar 2023 21:12:40 +0000 (17:12 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 11 Apr 2023 19:40:45 +0000 (19:40 +0000)
For #57001, compilers and others tools will need to understand that
a different Go version can be used in different files in a program,
according to the //go:build lines in those files.

This CL adds a GoVersion string field to ast.File, to allow exposing this
per-file Go version information.

For #59033.

Change-Id: I3931ea86c237983d152964f48dce498bcb1f06aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/476276
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>

api/next/59033.txt
src/go/ast/ast.go
src/go/ast/example_test.go
src/go/ast/filter.go

index 4c376974628c19a83a9aa7426b319aabfe11b080..d3b319c4834f84d92b521814681cca7f5ed83f75 100644 (file)
@@ -1,2 +1,3 @@
+pkg go/ast, type File struct, GoVersion string #59033
 pkg go/build/constraint, func GoVersion(Expr) string #59033
 
index 9baf72f40f785b109e92287bb1cac36df821bc2e..b509ef1a70bec9df5b424ed904429536a93dfee6 100644 (file)
@@ -1046,6 +1046,7 @@ type File struct {
        Imports            []*ImportSpec   // imports in this file
        Unresolved         []*Ident        // unresolved identifiers in this file
        Comments           []*CommentGroup // list of all comments in the source file
+       GoVersion          string          // minimum Go version required by //go:build or // +build directives
 }
 
 // Pos returns the position of the package declaration.
index c6904be6e553e6f10be14646021484692c3d23f7..4ce42fb1536be09f31cd0b4c1b7512abc041f17f 100644 (file)
@@ -136,7 +136,8 @@ func main() {
        //     57  .  Unresolved: []*ast.Ident (len = 1) {
        //     58  .  .  0: *(obj @ 29)
        //     59  .  }
-       //     60  }
+       //     60  .  GoVersion: ""
+       //     61  }
 }
 
 // This example illustrates how to remove a variable declaration
index 7d2a11e4750b487f893e64085d48237366acc607..c9e733a5a52c4efc9cb9cbd87245830a2290c767 100644 (file)
@@ -491,5 +491,5 @@ func MergePackageFiles(pkg *Package, mode MergeMode) *File {
        }
 
        // TODO(gri) need to compute unresolved identifiers!
-       return &File{doc, pos, NewIdent(pkg.Name), decls, minPos, maxPos, pkg.Scope, imports, nil, comments}
+       return &File{doc, pos, NewIdent(pkg.Name), decls, minPos, maxPos, pkg.Scope, imports, nil, comments, ""}
 }