Commit c8c1c3f7 authored by Etienne Renault's avatar Etienne Renault

desugararray: no special case for index 0

The previous code considered index 0 as a special case.
Thus the transformation wasn't go-compiliant after this
pass which was bad.

* transform/desugararray.go: Here.
parent 9a3041b6
......@@ -76,9 +76,8 @@ func (t *DesugarArray) Pre(meta *Meta, v *Visitor) bool {
switch init := node.Values[0].(type) {
case *ast.CompositeLit:
// All but first must be registered
var res []*ast.AssignStmt
for i := 1; i < size; i++ {
for i := 0; i < size; i++ {
res = append(res, &ast.AssignStmt{
Lhs: []ast.Expr{
&ast.IndexExpr{
......@@ -106,7 +105,7 @@ func (t *DesugarArray) Pre(meta *Meta, v *Visitor) bool {
// First is trivially settabble
if len(init.Elts) != 0 {
node.Values = []ast.Expr{init.Elts[0]}
node.Values = nil
}
default:
......@@ -123,9 +122,8 @@ func (t *DesugarArray) Pre(meta *Meta, v *Visitor) bool {
size := len(init.Elts)
meta.RegisterArray(node.Names[0].Name, t.currentFuncName, size)
// All but first must be registered
var res []*ast.AssignStmt
for i := 1; i < size; i++ {
for i := 0; i < size; i++ {
res = append(res, &ast.AssignStmt{
Lhs: []ast.Expr{
&ast.IndexExpr{
......@@ -153,7 +151,7 @@ func (t *DesugarArray) Pre(meta *Meta, v *Visitor) bool {
// First is trivially settabble
if len(init.Elts) != 0 {
node.Values = []ast.Expr{init.Elts[0]}
node.Values = nil
}
default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment