Skip to content

Commit f9f582e

Browse files
committed
go/packages: pass go list-reported Go language version to type checker
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 <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Russ Cox <[email protected]>
1 parent e7916d0 commit f9f582e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

go/packages/packages.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,9 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
10431043
Error: appendError,
10441044
Sizes: ld.sizes,
10451045
}
1046+
if lpkg.Module != nil && lpkg.Module.GoVersion != "" {
1047+
typesinternal.SetGoVersion(tc, "go"+lpkg.Module.GoVersion)
1048+
}
10461049
if (ld.Mode & typecheckCgo) != 0 {
10471050
if !typesinternal.SetUsesCgo(tc) {
10481051
appendError(Error{

0 commit comments

Comments
 (0)