Skip to content

Commit

Permalink
go/packages: pass go list-reported Go language version to type checker
Browse files Browse the repository at this point in the history
Type checking of a package depends on the Go language version in
effect for that package. We have been not setting it and assuming
"latest" is good enough, but that is likely to become untrue in the
future, and it violates Go 1.21's emphasis on forward compatibility,
namely tools recognizing when they shouldn't be processing newer code.

Pass the Go version along from go/packages to go/types, to allow
go/types to apply the version when type-checking.

This is tested by CL 507880.

For golang/go#61174.

Change-Id: I49353dede9c7c095c2cd0c4a6959f9f6e6a06ec5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/507879
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
  • Loading branch information
rsc committed Jul 6, 2023
1 parent e7916d0 commit f9f582e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,9 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
Error: appendError,
Sizes: ld.sizes,
}
if lpkg.Module != nil && lpkg.Module.GoVersion != "" {
typesinternal.SetGoVersion(tc, "go"+lpkg.Module.GoVersion)
}
if (ld.Mode & typecheckCgo) != 0 {
if !typesinternal.SetUsesCgo(tc) {
appendError(Error{
Expand Down

0 comments on commit f9f582e

Please sign in to comment.