mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile: simplify NewClosureFunc
I initially made NewClosureFunc take an "outerfn *Func" parameter because I was planning on having it handle closure naming, until remembering that naming needs to wait until typecheck for noder. We don't actually need the *Func yet, just to know whether it's non-nil. So change the parameter to a bool, which simplifies callers a little. Change-Id: Ie83ee4a1ed0571ac6d3879ffd8474c6c3c1a9ff9 Reviewed-on: https://go-review.googlesource.com/c/go/+/327450 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
db7c868307
commit
f1b1c2f67f
7 changed files with 20 additions and 20 deletions
|
|
@ -343,11 +343,13 @@ func closureName(outerfn *Func) *types.Sym {
|
|||
return pkg.Lookup(fmt.Sprintf("%s.%s%d", outer, prefix, *gen))
|
||||
}
|
||||
|
||||
// NewClosureFunc creates a new Func to represent a function literal
|
||||
// within outerfn.
|
||||
func NewClosureFunc(pos src.XPos, outerfn *Func) *Func {
|
||||
// NewClosureFunc creates a new Func to represent a function literal.
|
||||
// If hidden is true, then the closure is marked hidden (i.e., as a
|
||||
// function literal contained within another function, rather than a
|
||||
// package-scope variable initialization expression).
|
||||
func NewClosureFunc(pos src.XPos, hidden bool) *Func {
|
||||
fn := NewFunc(pos)
|
||||
fn.SetIsHiddenClosure(outerfn != nil)
|
||||
fn.SetIsHiddenClosure(hidden)
|
||||
|
||||
fn.Nname = NewNameAt(pos, BlankNode.Sym())
|
||||
fn.Nname.Func = fn
|
||||
|
|
@ -361,7 +363,12 @@ func NewClosureFunc(pos src.XPos, outerfn *Func) *Func {
|
|||
// NameClosure generates a unique for the given function literal,
|
||||
// which must have appeared within outerfn.
|
||||
func NameClosure(clo *ClosureExpr, outerfn *Func) {
|
||||
name := clo.Func.Nname
|
||||
fn := clo.Func
|
||||
if fn.IsHiddenClosure() != (outerfn != nil) {
|
||||
base.FatalfAt(clo.Pos(), "closure naming inconsistency: hidden %v, but outer %v", fn.IsHiddenClosure(), outerfn)
|
||||
}
|
||||
|
||||
name := fn.Nname
|
||||
if !IsBlank(name) {
|
||||
base.FatalfAt(clo.Pos(), "closure already named: %v", name)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue