PackageFile: make(map[string]string),
Standard: make(map[string]bool),
}
+ vcfg.GoVersion = "go" + gover.Local()
if a.Package.Module != nil {
v := a.Package.Module.GoVersion
if v == "" {
pkgpath := pkgPath(a)
defaultGcFlags := []string{"-p", pkgpath}
+ vers := gover.Local()
if p.Module != nil {
v := p.Module.GoVersion
if v == "" {
v = gover.DefaultGoModVersion
}
+ // TODO(samthanawalla): Investigate when allowedVersion is not true.
if allowedVersion(v) {
- defaultGcFlags = append(defaultGcFlags, "-lang=go"+gover.Lang(v))
+ vers = v
}
}
+ defaultGcFlags = append(defaultGcFlags, "-lang=go"+gover.Lang(vers))
if p.Standard {
defaultGcFlags = append(defaultGcFlags, "-std")
}
--- /dev/null
+# go.dev/issue/66092
+# This test ensures that files listed on the commandline will pass
+# the language version to the compiler.
+# All compilations should specify some -lang.
+
+go build -n x.go
+stderr '-lang=go1\.[0-9]+'
+
+-- x.go --
+package main
\ No newline at end of file
--- /dev/null
+# go.dev/issue/65612
+# go vet should set the GoVersion for command line files.
+
+env TESTGO_VERSION=go1.22.1
+env TESTGO_VERSION_SWITCH=switch
+
+go vet -n -json example.com/m
+stderr '"GoVersion": "go1.22.0"'
+
+# A command line file should use the local go version.
+go vet -n -json main.go
+stderr '"GoVersion": "go1.22.1"'
+
+# In workspace mode, the command line file version should use go.work version.
+cp go.work.orig go.work
+go vet -n -json example.com/m
+stderr '"GoVersion": "go1.22.0'
+
+go vet -n -json main.go
+stderr '"GoVersion": "go1.22.2'
+
+# Without go.mod or go.work, the command line file version should use local go version .
+env TESTGO_VERSION=go1.22.3
+rm go.mod
+rm go.work
+
+! go vet -n -json example.com/m
+
+go vet -n -json main.go
+stderr '"GoVersion": "go1.22.3"'
+
+-- go.mod --
+module example.com/m
+
+go 1.22.0
+
+-- go.work.orig --
+go 1.22.2
+
+use .
+
+-- main.go --
+package main