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>
This commit is contained in:
Robert Griesemer 2021-04-26 12:50:44 -07:00
parent 9f601690da
commit be28caf0aa
2 changed files with 18 additions and 12 deletions

View file

@ -1132,6 +1132,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
case *syntax.FuncLit: case *syntax.FuncLit:
if sig, ok := check.typ(e.Type).(*Signature); ok { if sig, ok := check.typ(e.Type).(*Signature); ok {
if !check.conf.IgnoreFuncBodies && e.Body != nil {
// Anonymous functions are considered part of the // Anonymous functions are considered part of the
// init expression/func declaration which contains // init expression/func declaration which contains
// them: use existing package-level declaration info. // them: use existing package-level declaration info.
@ -1144,6 +1145,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
check.later(func() { check.later(func() {
check.funcBody(decl, "<function literal>", sig, e.Body, iota) check.funcBody(decl, "<function literal>", sig, e.Body, iota)
}) })
}
x.mode = value x.mode = value
x.typ = sig x.typ = sig
} else { } else {

View file

@ -13,6 +13,10 @@ import (
) )
func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *syntax.BlockStmt, iota constant.Value) { 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 { if check.conf.Trace {
check.trace(body.Pos(), "--- %s: %s", name, sig) check.trace(body.Pos(), "--- %s: %s", name, sig)
defer func() { defer func() {