aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/iimport.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-09-19 09:23:21 -0700
committerDan Scales <danscales@google.com>2021-09-20 00:13:47 +0000
commita83a5587331392fc9483d183e446586b463ad8aa (patch)
treede595f2e4e9c85f89ff71f46ddb5befc21794847 /src/cmd/compile/internal/typecheck/iimport.go
parent315dbd10c90db3b41af2c975a5fbfa2ec7615c1b (diff)
downloadgo-a83a5587331392fc9483d183e446586b463ad8aa.tar.gz
go-a83a5587331392fc9483d183e446586b463ad8aa.zip
cmd/compile: fix export/import of range loop.
As with other recent issues, the Init field of a range loop was not being handled properly. Generally, it is much better to explicitly import/export the Init statements, else they are incorrectly added before the associated node, rather than as the Init value of the node. This was causing labels to not be correctly added to the range loop that it is immediately preceding. Made the ORANGE handling completely similar to the OFOR handling. Fixes #48462 Change-Id: I999530e84f9357f81deaa3dda50660061f710e7c Reviewed-on: https://go-review.googlesource.com/c/go/+/350911 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.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.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index 3b3c2a2e2a..a7339903fc 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -1515,7 +1515,7 @@ func (r *importReader) node() ir.Node {
if go117ExportTypes {
n.SetOp(op)
}
- *n.PtrInit() = init
+ n.SetInit(init)
n.IsDDD = r.bool()
if go117ExportTypes {
n.SetType(r.exoticType())
@@ -1660,26 +1660,28 @@ func (r *importReader) node() ir.Node {
case ir.OIF:
pos, init := r.pos(), r.stmtList()
n := ir.NewIfStmt(pos, r.expr(), r.stmtList(), r.stmtList())
- *n.PtrInit() = init
+ n.SetInit(init)
return n
case ir.OFOR:
pos, init := r.pos(), r.stmtList()
cond, post := r.exprsOrNil()
n := ir.NewForStmt(pos, nil, cond, post, r.stmtList())
- *n.PtrInit() = init
+ n.SetInit(init)
return n
case ir.ORANGE:
- pos := r.pos()
+ pos, init := r.pos(), r.stmtList()
k, v := r.exprsOrNil()
- return ir.NewRangeStmt(pos, k, v, r.expr(), r.stmtList())
+ n := ir.NewRangeStmt(pos, k, v, r.expr(), r.stmtList())
+ n.SetInit(init)
+ return n
case ir.OSELECT:
pos := r.pos()
init := r.stmtList()
n := ir.NewSelectStmt(pos, r.commList())
- *n.PtrInit() = init
+ n.SetInit(init)
return n
case ir.OSWITCH:
@@ -1687,7 +1689,7 @@ func (r *importReader) node() ir.Node {
init := r.stmtList()
x, _ := r.exprsOrNil()
n := ir.NewSwitchStmt(pos, x, r.caseList(x))
- *n.PtrInit() = init
+ n.SetInit(init)
return n
// case OCASE: