]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: respect IgnoreFuncBodies for function literals
authorRobert Griesemer <gri@golang.org>
Mon, 26 Apr 2021 19:50:44 +0000 (12:50 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 26 Apr 2021 21:35:26 +0000 (21:35 +0000)
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>

src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/stmt.go

index 76c6e7a3b30cb48b744fc8d5f6f42724c74167e6..8dbe6ea5379a19ec2d6451237cccfad21e07d77c 100644 (file)
@@ -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 {
index 9e3a45b6a8cd587a1c37056b5ba973a0b574b330..c3e646c80c142d91434991bc5f37d57ab20d4225 100644 (file)
@@ -13,6 +13,10 @@ import (
 )
 
 func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *syntax.BlockStmt, iota constant.Value) {
+       if check.conf.IgnoreFuncBodies {
+               panic("internal error: function body not ignored")
+       }
+
        if check.conf.Trace {
                check.trace(body.Pos(), "--- %s: %s", name, sig)
                defer func() {