-
Notifications
You must be signed in to change notification settings - Fork 18k
go/types: add Package.GoVersion method #61175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I take back it not being necessary. Checkers like cgocall re-typecheck certain files and need to be able to propagate the language version. Adding this method means we can use:
|
Change https://go.dev/cl/507975 mentions this issue: |
Change https://go.dev/cl/507880 mentions this issue: |
This makes sense to me. I don't think it's strictly necessary, since it would be possible for any caller (such as an analysis driver) to keep track of its own inputs. However, since the version is unambiguously associated with the resulting package, it make sense to capture it in the package directly. |
At the very least it seems to be necessary for |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
…method Clients of go/types, such as analyzers, may need to know which specific Go version a package is written for. Record that information in the Package and expose it using the new GoVersion method. Update parseGoVersion to handle the new Go versions that may be passed around starting in Go 1.21.0: versions like "go1.21.0" and "go1.21rc2". This is not strictly necessary today, but it adds some valuable future-proofing. While we are here, change NewChecker from panicking on invalid version to saving an error for returning later from Files. Go versions are now likely to be coming from a variety of sources, not just hard-coded in calls to NewChecker, making a panic inappropriate. For golang#61174. Fixes golang#61175. Change-Id: Ibe41fe207c1b6e71064b1fe448ac55776089c541 Reviewed-on: https://go-review.googlesource.com/c/go/+/507975 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
Change https://go.dev/cl/511096 mentions this issue: |
Update the documentation for Config.GoVersion to reflect the changes made for #61175. Change-Id: I9f3fbcf8ee88e52d6a5e7cf80dad3d2fb5313893 Reviewed-on: https://go-review.googlesource.com/c/go/+/511096 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Change https://go.dev/cl/511699 mentions this issue: |
…Version Update the documentation for Config.GoVersion to reflect the changes made for #61175. Change-Id: I9f3fbcf8ee88e52d6a5e7cf80dad3d2fb5313893 Reviewed-on: https://go-review.googlesource.com/c/go/+/511096 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> (cherry picked from commit 12f3d68) Reviewed-on: https://go-review.googlesource.com/c/go/+/511699 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
…Version Update the documentation for Config.GoVersion to reflect the changes made for golang#61175. Change-Id: I9f3fbcf8ee88e52d6a5e7cf80dad3d2fb5313893 Reviewed-on: https://go-review.googlesource.com/c/go/+/511096 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> (cherry picked from commit 12f3d68) Reviewed-on: https://go-review.googlesource.com/c/go/+/511699 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
…method Clients of go/types, such as analyzers, may need to know which specific Go version a package is written for. Record that information in the Package and expose it using the new GoVersion method. Update parseGoVersion to handle the new Go versions that may be passed around starting in Go 1.21.0: versions like "go1.21.0" and "go1.21rc2". This is not strictly necessary today, but it adds some valuable future-proofing. While we are here, change NewChecker from panicking on invalid version to saving an error for returning later from Files. Go versions are now likely to be coming from a variety of sources, not just hard-coded in calls to NewChecker, making a panic inappropriate. For golang#61174. Fixes golang#61175. Change-Id: Ibe41fe207c1b6e71064b1fe448ac55776089c541 Reviewed-on: https://go-review.googlesource.com/c/go/+/507975 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
For #61174, it would be good for individual checkers to be able to find out the Go version associated with a given package. The code will start tracking this, but we should export it as well. Strictly speaking this is not necessary for Go 1.21, but I suggest we include it now, since it will be necessary for Go 1.22 and it will be easier for tool authors if all the related changes are in the same Go version.
The new method is:
The goVersion is set during type-checking, copied from Config.GoVersion.
The text was updated successfully, but these errors were encountered: