In this example
-- go.mod --
module example.com
go 1.23
-- foo.go --
//go:build go1.21
package pkg
import "reflect"
func main() {
_ = reflect.TypeFor[int]
}
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.
/cc @adonovan
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:builddirective 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 thegodependency 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