aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-04-28 11:13:35 -0400
committerRobert Findley <rfindley@google.com>2021-04-28 20:36:50 +0000
commitfa6ed6e81ae6414681336c08da16213b943c45e3 (patch)
tree78be8c02eaf834c47dc4e14f196a6ac466394855 /src/go
parent6082c05d8b4ab59e74204a3749629c8e6240b7b0 (diff)
downloadgo-fa6ed6e81ae6414681336c08da16213b943c45e3.tar.gz
go-fa6ed6e81ae6414681336c08da16213b943c45e3.zip
go/types: respect IgnoreFuncBodies for function literals
This is a 1:1 port of CL 313650 to go/types. Change-Id: Iec01ac2831f21162d9977a139549e081ee769f90 Reviewed-on: https://go-review.googlesource.com/c/go/+/314631 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/types/expr.go26
-rw-r--r--src/go/types/stmt.go4
2 files changed, 18 insertions, 12 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index 4055cdd080..9bfe23a815 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -1085,18 +1085,20 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
case *ast.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 {
diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go
index 27da198a85..47f6dcfbd1 100644
--- a/src/go/types/stmt.go
+++ b/src/go/types/stmt.go
@@ -14,6 +14,10 @@ import (
)
func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *ast.BlockStmt, iota constant.Value) {
+ if check.conf.IgnoreFuncBodies {
+ panic("internal error: function body not ignored")
+ }
+
if trace {
check.trace(body.Pos(), "--- %s: %s", name, sig)
defer func() {