mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
6082c05d8b
commit
fa6ed6e81a
2 changed files with 18 additions and 12 deletions
|
|
@ -1085,18 +1085,20 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
||||||
|
|
||||||
case *ast.FuncLit:
|
case *ast.FuncLit:
|
||||||
if sig, ok := check.typ(e.Type).(*Signature); ok {
|
if sig, ok := check.typ(e.Type).(*Signature); ok {
|
||||||
// Anonymous functions are considered part of the
|
if !check.conf.IgnoreFuncBodies && e.Body != nil {
|
||||||
// init expression/func declaration which contains
|
// Anonymous functions are considered part of the
|
||||||
// them: use existing package-level declaration info.
|
// init expression/func declaration which contains
|
||||||
decl := check.decl // capture for use in closure below
|
// them: use existing package-level declaration info.
|
||||||
iota := check.iota // capture for use in closure below (#22345)
|
decl := check.decl // capture for use in closure below
|
||||||
// Don't type-check right away because the function may
|
iota := check.iota // capture for use in closure below (#22345)
|
||||||
// be part of a type definition to which the function
|
// Don't type-check right away because the function may
|
||||||
// body refers. Instead, type-check as soon as possible,
|
// be part of a type definition to which the function
|
||||||
// but before the enclosing scope contents changes (#22992).
|
// body refers. Instead, type-check as soon as possible,
|
||||||
check.later(func() {
|
// but before the enclosing scope contents changes (#22992).
|
||||||
check.funcBody(decl, "<function literal>", sig, e.Body, iota)
|
check.later(func() {
|
||||||
})
|
check.funcBody(decl, "<function literal>", sig, e.Body, iota)
|
||||||
|
})
|
||||||
|
}
|
||||||
x.mode = value
|
x.mode = value
|
||||||
x.typ = sig
|
x.typ = sig
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *ast.BlockStmt, iota constant.Value) {
|
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 {
|
if trace {
|
||||||
check.trace(body.Pos(), "--- %s: %s", name, sig)
|
check.trace(body.Pos(), "--- %s: %s", name, sig)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue