]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: move //go:embed -lang check to noder
authorMatthew Dempsky <mdempsky@google.com>
Sun, 13 Jun 2021 01:44:51 +0000 (18:44 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Sun, 13 Jun 2021 03:10:49 +0000 (03:10 +0000)
User errors should be reported in noder and/or typecheck, we already
know the -lang flag's value during noding, and checking it then works
better for unified IR.

The "multiple files for type" and "cannot apply to var of type" errors
should also be moved to typecheck, but then they'd have to be
duplicated for -G=3 mode (because it avoids typecheck). So those are
left behind for now.

Change-Id: I7caf16163c9faf975784acacdb8147514d2e698e
Reviewed-on: https://go-review.googlesource.com/c/go/+/327609
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/staticdata/embed.go

index 63822d308930650614ca6374d4c684dcc4f539f7..d417edcbd526cc47e8156b326e8c75bd34d523f7 100644 (file)
@@ -1886,6 +1886,8 @@ 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):
+               return fmt.Errorf("go:embed requires go1.16 or later (-lang was set to %s; check go.mod)", base.Flag.Lang)
 
        default:
                return nil
index 8936c4f5b44e44c7f03edf81a137e49eb68ac564..0730d346b2402da1c9e7ea65f8bc1106b3559ed2 100644 (file)
@@ -108,13 +108,6 @@ func WriteEmbed(v *ir.Name) {
        // TODO(mdempsky): User errors should be reported by the frontend.
 
        commentPos := (*v.Embed)[0].Pos
-       if !types.AllowsGoVersion(types.LocalPkg, 1, 16) {
-               prevPos := base.Pos
-               base.Pos = commentPos
-               base.ErrorfVers("go1.16", "go:embed")
-               base.Pos = prevPos
-               return
-       }
        if base.Flag.Cfg.Embed.Patterns == nil {
                base.ErrorfAt(commentPos, "invalid go:embed: build system did not supply embed configuration")
                return