]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types: simplify AllowsGoVersion
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 23 Mar 2022 10:13:38 +0000 (17:13 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 23 Mar 2022 19:31:59 +0000 (19:31 +0000)
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>
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/types/goversion.go

index 1d7c1f44a426fb1201a7e6c165b162c2d9db3535..f8f802936be06d217e472c5a0caeb2439de2227d 100644 (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:
index 1a324aa42fdb70de258ce6abfbc12dabf2505bca..ceb2ed366edae03481029d3025d80d2995989114 100644 (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
        }