Skip to content

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

@dominikh

Description

@dominikh

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

Metadata

Metadata

Assignees

No one assigned

    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.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions