aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/iimport.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-03-01 09:05:58 -0800
committerDan Scales <danscales@google.com>2021-03-01 20:59:43 +0000
commitb98ce3b606b2bb620c9c62482cd73f068157a32c (patch)
treed064283ac920038f0f16f213294a2282bc85d2eb /src/cmd/compile/internal/typecheck/iimport.go
parent97bdac03aee805cfa54e7762037a568d85339970 (diff)
downloadgo-b98ce3b606b2bb620c9c62482cd73f068157a32c.tar.gz
go-b98ce3b606b2bb620c9c62482cd73f068157a32c.zip
cmd/compile: import empty closure function correctly
On import, make sure that an empty closure is represented as a single empty block statement. Otherwise, the closure is dropped. Block statements are not exported explicitly, so must recreate on import. Fixes #44330 Change-Id: I061598f0f859dd71d2d0cbd10c77cdd81525d1f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/297569 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iimport.go')
-rw-r--r--src/cmd/compile/internal/typecheck/iimport.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index 17aa35549d..9355174da8 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -992,6 +992,11 @@ func (r *importReader) node() ir.Node {
r.funcBody(fn)
fn.Dcl = fn.Inl.Dcl
fn.Body = fn.Inl.Body
+ if len(fn.Body) == 0 {
+ // An empty closure must be represented as a single empty
+ // block statement, else it will be dropped.
+ fn.Body = []ir.Node{ir.NewBlockStmt(src.NoXPos, nil)}
+ }
fn.Inl = nil
ir.FinishCaptureNames(pos, r.curfn, fn)