g.target.Inits = append(g.target.Inits, fn)
}
+ haveEmbed := g.haveEmbed
g.later(func() {
+ defer func(b bool) { g.haveEmbed = b }(g.haveEmbed)
+
+ g.haveEmbed = haveEmbed
if fn.Type().HasTParam() {
g.topFuncIsGeneric = true
}
if decl.Pragma != nil {
pragma := decl.Pragma.(*pragmas)
- // TODO(mdempsky): Plumb noder.importedEmbed through to here.
- varEmbed(g.makeXPos, names[0], decl, pragma, true)
+ varEmbed(g.makeXPos, names[0], decl, pragma, g.haveEmbed)
g.reportUnused(pragma)
}
+ haveEmbed := g.haveEmbed
do := func() {
+ defer func(b bool) { g.haveEmbed = b }(g.haveEmbed)
+
+ g.haveEmbed = haveEmbed
values := g.exprList(decl.Values)
var as2 *ir.AssignListStmt
// laterFuncs records tasks that need to run after all declarations
// are processed.
laterFuncs []func()
+ // haveEmbed indicates whether the current node belongs to file that
+ // imports "embed" package.
+ haveEmbed bool
// exprStmtOK indicates whether it's safe to generate expressions or
// statements yet.
types.ResumeCheckSize()
// 3. Process all remaining declarations.
- for _, declList := range declLists {
+ for i, declList := range declLists {
+ old := g.haveEmbed
+ g.haveEmbed = noders[i].importedEmbed
g.decls((*ir.Nodes)(&g.target.Decls), declList)
+ g.haveEmbed = old
}
g.exprStmtOK = true
"issue42058a.go", // types2 does not have constraints on channel element size
"issue42058b.go", // types2 does not have constraints on channel element size
"issue48097.go", // go/types doesn't check validity of //go:xxx directives, and non-init bodyless function
-
+ "issue48230.go", // go/types doesn't check validity of //go:xxx directives
)
}
"issue42058a.go", // go/types does not have constraints on channel element size
"issue42058b.go", // go/types does not have constraints on channel element size
"issue48097.go", // go/types doesn't check validity of //go:xxx directives, and non-init bodyless function
+ "issue48230.go", // go/types doesn't check validity of //go:xxx directives
)
}
--- /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
+
+//go:embed issue48230.go // ERROR `go:embed only allowed in Go files that import "embed"`
+var _ string