aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/walk/complit.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile/internal/walk/complit.go')
-rw-r--r--src/cmd/compile/internal/walk/complit.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go
index 595fe8538c..7dec9ae6d8 100644
--- a/src/cmd/compile/internal/walk/complit.go
+++ b/src/cmd/compile/internal/walk/complit.go
@@ -414,9 +414,10 @@ func slicelit(ctxt initContext, n *ir.CompLitExpr, var_ ir.Node, init *ir.Nodes)
func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
// make the map var
- a := ir.NewCallExpr(base.Pos, ir.OMAKE, nil, nil)
+ args := []ir.Node{ir.TypeNode(n.Type()), ir.NewInt(n.Len + int64(len(n.List)))}
+ a := typecheck.Expr(ir.NewCallExpr(base.Pos, ir.OMAKE, nil, args)).(*ir.MakeExpr)
+ a.RType = n.RType
a.SetEsc(n.Esc())
- a.Args = []ir.Node{ir.TypeNode(n.Type()), ir.NewInt(n.Len + int64(len(n.List)))}
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, m, a))
entries := n.List
@@ -467,14 +468,18 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
kidx := ir.NewIndexExpr(base.Pos, vstatk, i)
kidx.SetBounded(true)
- lhs := ir.NewIndexExpr(base.Pos, m, kidx)
+
+ // typechecker rewrites OINDEX to OINDEXMAP
+ lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, kidx)).(*ir.IndexExpr)
+ base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
+ lhs.RType = n.RType
zero := ir.NewAssignStmt(base.Pos, i, ir.NewInt(0))
cond := ir.NewBinaryExpr(base.Pos, ir.OLT, i, ir.NewInt(tk.NumElem()))
incr := ir.NewAssignStmt(base.Pos, i, ir.NewBinaryExpr(base.Pos, ir.OADD, i, ir.NewInt(1)))
var body ir.Node = ir.NewAssignStmt(base.Pos, lhs, rhs)
- body = typecheck.Stmt(body) // typechecker rewrites OINDEX to OINDEXMAP
+ body = typecheck.Stmt(body)
body = orderStmtInPlace(body, map[string][]*ir.Name{})
loop := ir.NewForStmt(base.Pos, nil, cond, incr, nil)
@@ -503,8 +508,14 @@ func maplit(n *ir.CompLitExpr, m ir.Node, init *ir.Nodes) {
appendWalkStmt(init, ir.NewAssignStmt(base.Pos, tmpelem, elem))
ir.SetPos(tmpelem)
- var a ir.Node = ir.NewAssignStmt(base.Pos, ir.NewIndexExpr(base.Pos, m, tmpkey), tmpelem)
- a = typecheck.Stmt(a) // typechecker rewrites OINDEX to OINDEXMAP
+
+ // typechecker rewrites OINDEX to OINDEXMAP
+ lhs := typecheck.AssignExpr(ir.NewIndexExpr(base.Pos, m, tmpkey)).(*ir.IndexExpr)
+ base.AssertfAt(lhs.Op() == ir.OINDEXMAP, lhs.Pos(), "want OINDEXMAP, have %+v", lhs)
+ lhs.RType = n.RType
+
+ var a ir.Node = ir.NewAssignStmt(base.Pos, lhs, tmpelem)
+ a = typecheck.Stmt(a)
a = orderStmtInPlace(a, map[string][]*ir.Name{})
appendWalkStmt(init, a)
}