From: Rob Findley Date: Wed, 28 Apr 2021 15:13:35 +0000 (-0400) Subject: go/types: respect IgnoreFuncBodies for function literals X-Git-Tag: go1.17beta1~376 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fa6ed6e81a;p=gostls13.git 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 Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- 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, "", 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, "", 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() {