1
0
mirror of https://github.com/golang/go synced 2024-11-17 09:54:46 -07:00

cmd/compile/internal/types: simplify AllowsGoVersion

After CL 394556, only LocalPkg is passed to AllowsGoVersion, so simplify
the code to not depend on Pkg anymore.

Change-Id: I8f9bfd4090100eec60cf3959c0d8fa92a26fc32a
Reviewed-on: https://go-review.googlesource.com/c/go/+/394954
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2022-03-23 17:13:38 +07:00
parent 0eb2c77124
commit 947bf333fc
2 changed files with 4 additions and 14 deletions

View File

@ -472,7 +472,7 @@ func checkEmbed(decl *syntax.VarDecl, haveEmbed, withinFunc bool) error {
return errors.New("go:embed cannot apply to var without type")
case withinFunc:
return errors.New("go:embed cannot apply to var inside func")
case !types.AllowsGoVersion(types.LocalPkg, 1, 16):
case !types.AllowsGoVersion(1, 16):
return fmt.Errorf("go:embed requires go1.16 or later (-lang was set to %s; check go.mod)", base.Flag.Lang)
default:

View File

@ -24,19 +24,9 @@ type lang struct {
// any language version is supported.
var langWant lang
// AllowsGoVersion reports whether a particular package
// is allowed to use Go version major.minor.
// We assume the imported packages have all been checked,
// so we only have to check the local package against the -lang flag.
func AllowsGoVersion(pkg *Pkg, major, minor int) bool {
if pkg == nil {
// TODO(mdempsky): Set Pkg for local types earlier.
pkg = LocalPkg
}
if pkg != LocalPkg {
// Assume imported packages passed type-checking.
return true
}
// AllowsGoVersion reports whether local package is allowed
// to use Go version major.minor.
func AllowsGoVersion(major, minor int) bool {
if langWant.major == 0 && langWant.minor == 0 {
return true
}