golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.88k stars 17.52k forks source link

x/tools/go/analysis/passes/stdversion: language vs toolchain version #68246

Open dominikh opened 2 months ago

dominikh commented 2 months ago

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

gabyhelp commented 2 months ago

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)