p.yyerrorpos(pos, "invalid go:embed: missing import \"embed\"")
return
}
- if embedCfg.Patterns == nil {
- p.yyerrorpos(pos, "invalid go:embed: build system did not supply embed configuration")
- return
- }
if len(names) > 1 {
p.yyerrorpos(pos, "go:embed cannot apply to multiple vars")
return
// initEmbed emits the init data for a //go:embed variable,
// which is either a string, a []byte, or an embed.FS.
func initEmbed(v *Node) {
+ commentPos := v.Name.Param.EmbedList()[0].Pos
+ if !langSupported(1, 16, localpkg) {
+ lno := lineno
+ lineno = commentPos
+ yyerrorv("go1.16", "go:embed")
+ lineno = lno
+ return
+ }
+ if embedCfg.Patterns == nil {
+ yyerrorl(commentPos, "invalid go:embed: build system did not supply embed configuration")
+ return
+ }
kind := embedKind(v.Type)
if kind == embedUnknown {
yyerrorl(v.Pos, "go:embed cannot apply to var of type %v", v.Type)
testTestDir(t, filepath.Join(runtime.GOROOT(), "test"),
"cmplxdivide.go", // also needs file cmplxdivide1.go - ignore
"directive.go", // tests compiler rejection of bad directive placement - ignore
+ "embedfunc.go", // tests //go:embed
+ "embedvers.go", // tests //go:embed
)
}
--- /dev/null
+// errorcheck
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+import _ "embed"
+
+func f() {
+ //go:embed x.txt // ERROR "go:embed cannot apply to var inside func"
+ var x string
+ _ = x
+}
--- /dev/null
+// errorcheck -lang=go1.15
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+import _ "embed"
+
+//go:embed x.txt // ERROR "go:embed requires go1.16 or later"
+var x string