]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: respect IgnoreFuncBodies for function literals
authorRob Findley <rfindley@google.com>
Wed, 28 Apr 2021 15:13:35 +0000 (11:13 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 28 Apr 2021 20:36:50 +0000 (20:36 +0000)
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>
src/go/types/expr.go
src/go/types/stmt.go

index 4055cdd080c01add3b5985c5ed26e7a90389ceb0..9bfe23a8151b5a1f864879f519d55d727941b8a3 100644 (file)
@@ -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 {
index 27da198a850aa3fdc126c65a039576bef67c4947..47f6dcfbd1ce8f6f5b25f0da36a2ef144afb1feb 100644 (file)
@@ -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() {