diff options
author | Robert Griesemer <gri@golang.org> | 2021-04-26 12:50:44 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-04-26 21:35:26 +0000 |
commit | be28caf0aa1649c4422f64e687a388a027686e6e (patch) | |
tree | 2cb81b4b666cace77155c0a9a5b1326b9d021852 /src/cmd/compile/internal/types2/expr.go | |
parent | 9f601690da59e601ff68f9868d5eb863bd770eae (diff) | |
download | go-be28caf0aa1649c4422f64e687a388a027686e6e.tar.gz go-be28caf0aa1649c4422f64e687a388a027686e6e.zip |
cmd/compile/internal/types2: respect IgnoreFuncBodies for function literals
Updates #45783.
Change-Id: Id552a60f262e2da62125acd6aec0901a82f5a29a
Reviewed-on: https://go-review.googlesource.com/c/go/+/313650
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2/expr.go')
-rw-r--r-- | src/cmd/compile/internal/types2/expr.go | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index 76c6e7a3b3..8dbe6ea537 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -1132,18 +1132,20 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin case *syntax.FuncLit: if sig, ok := check.typ(e.Type).(*Signature); ok { - // Anonymous functions are considered part of the - // init expression/func declaration which contains - // them: use existing package-level declaration info. - decl := check.decl // capture for use in closure below - iota := check.iota // capture for use in closure below (#22345) - // Don't type-check right away because the function may - // be part of a type definition to which the function - // body refers. Instead, type-check as soon as possible, - // but before the enclosing scope contents changes (#22992). - check.later(func() { - check.funcBody(decl, "<function literal>", sig, e.Body, iota) - }) + if !check.conf.IgnoreFuncBodies && e.Body != nil { + // Anonymous functions are considered part of the + // init expression/func declaration which contains + // them: use existing package-level declaration info. + decl := check.decl // capture for use in closure below + iota := check.iota // capture for use in closure below (#22345) + // Don't type-check right away because the function may + // be part of a type definition to which the function + // body refers. Instead, type-check as soon as possible, + // but before the enclosing scope contents changes (#22992). + check.later(func() { + check.funcBody(decl, "<function literal>", sig, e.Body, iota) + }) + } x.mode = value x.typ = sig } else { |