aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/iimport.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-04-11 09:47:13 -0700
committerDan Scales <danscales@google.com>2021-04-14 01:28:16 +0000
commiteb433ed5a2ab13567cd5d7f0413308174750d5dd (patch)
tree46a288276cc027b310388eb3498e07cef9de024e /src/cmd/compile/internal/typecheck/iimport.go
parent8dcc071063c0a9f020f0aafd51b7e0a17f0a0746 (diff)
downloadgo-eb433ed5a2ab13567cd5d7f0413308174750d5dd.tar.gz
go-eb433ed5a2ab13567cd5d7f0413308174750d5dd.zip
cmd/compile: set types properly for imported funcs with closures
For the new export/import of node types, we were just missing setting the types of the closure variables (which have the same types as the captured variables) and the OCLOSURE node itself (which has the same type as the Func node). Re-enabled inlining of functions with closures. Change-Id: I687149b061f3ffeec3244ff02dc6e946659077a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/308974 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/iimport.go')
-rw-r--r--src/cmd/compile/internal/typecheck/iimport.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index 0d5d892ef5..42c4619666 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -1112,6 +1112,14 @@ func (r *importReader) node() ir.Node {
cvars := make([]*ir.Name, r.int64())
for i := range cvars {
cvars[i] = ir.CaptureName(r.pos(), fn, r.localName().Canonical())
+ if go117ExportTypes {
+ if cvars[i].Type() != nil || cvars[i].Defn == nil {
+ base.Fatalf("bad import of closure variable")
+ }
+ // Closure variable should have Defn set, which is its captured
+ // variable, and it gets the same type as the captured variable.
+ cvars[i].SetType(cvars[i].Defn.Type())
+ }
}
fn.ClosureVars = cvars
r.allClosureVars = append(r.allClosureVars, cvars...)
@@ -1133,6 +1141,9 @@ func (r *importReader) node() ir.Node {
clo := ir.NewClosureExpr(pos, fn)
fn.OClosure = clo
+ if go117ExportTypes {
+ clo.SetType(typ)
+ }
return clo