You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dominikh opened this issue
Jun 28, 2024
· 3 comments
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.
stdversion reports ./foo.go:8:14: reflect.TypeFor requires go1.22 or later (file is go1.21)
I believe that this might be overly strict. Even though the //go:build directive downgrades the language version available in the file, it doesn't change the fact that this file will only be built by a toolchain that is at least verison 1.23, because the module as a whole will only be built by a toolchain that satisfies the go dependency in go.mod.
I thus believe that the standard library available to a file with a build tag is max(file's version, module's version), and not min.
Hi @dominikh, sorry for the delay. After a long discussion during which both @findleyr and I reversed ourselves, we agree that this is a bug. (Versioning is complex... @timothy-king wrote a talk laying out many aspects of it and how they interact, and I have long been meaning to distill these rules into a handy--or perhaps billboard-sized--flowchart for quick reference.)
The intent of the go1.21 build directive within a go1.23 module is to say: "the language features in this file should be downgraded to the semantics as they were in the go1.21 spec", but of course it will still be compiled and linked against the standard library of go1.23 or later. So this should disable go1.22 for-loop semantics (which could in theory be problematic for existing code), but should not prevent the file from accessing symbols of the go1.23+ library such as reflect.TypeFor.
In principle it may be impossible to use certain features of the go1.Y std library from a file tagged go1.X, where X < Y; for example, calling a generic library function from a source file that is not allowed to use generics. (So don't do that.)
I thus believe that the standard library available to a file with a build tag is max(file's version, module's version), and not min.
Agreed.
@rsc: Have we misremembered something from the long discussion we had when developing stdversion?
adonovan
added
NeedsFix
The path to resolution is known, but the work has not been done.
Analysis
Issues related to static analysis (vet, x/tools/go/analysis)
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Jan 24, 2025
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.
In this example
stdversion reports
./foo.go:8:14: reflect.TypeFor requires go1.22 or later (file is go1.21)
I believe that this might be overly strict. Even though the
//go:build
directive downgrades the language version available in the file, it doesn't change the fact that this file will only be built by a toolchain that is at least verison 1.23, because the module as a whole will only be built by a toolchain that satisfies thego
dependency ingo.mod
.I thus believe that the standard library available to a file with a build tag is
max(file's version, module's version)
, and notmin
./cc @adonovan
The text was updated successfully, but these errors were encountered: