]> Cypherpunks repositories - gostls13.git/commitdiff
[...] bug
authorKen Thompson <ken@golang.org>
Wed, 7 Jan 2009 21:20:10 +0000 (13:20 -0800)
committerKen Thompson <ken@golang.org>
Wed, 7 Jan 2009 21:20:10 +0000 (13:20 -0800)
R=r
OCL=22218
CL=22218

src/cmd/gc/go.h
src/cmd/gc/walk.c

index a5b103f5abbb8f42b6d948c6fe3c8c6f131e9ba8..042c1cf38eae80751b18303b15b77b83d41f4ec1 100644 (file)
@@ -836,3 +836,4 @@ void        argspace(int32);
 Node*  nodarg(Type*, int);
 void   nodconst(Node*, Type*, vlong);
 Type*  deep(Type*);
+Type*  shallow(Type*);
index 8e061cf8cb5a96f817c6167c60ee7479baffd130..37194a40b568b6049b1c77841719a2ac9055f1b6 100644 (file)
@@ -3556,38 +3556,44 @@ arraylit(Node *n)
        Iter saver;
        Type *t;
        Node *var, *r, *a, *nnew;
-       int idx, b;
+       int idx, ninit, b;
 
        t = n->type;
        if(t->etype != TARRAY)
                fatal("arraylit: not array");
 
+       // count initializers
+       ninit = 0;
+       r = listfirst(&saver, &n->left);
+       if(r != N && r->op == OEMPTY)
+               r = N;
+       while(r != N) {
+               ninit++;
+               r = listnext(&saver);
+       }
+
+       b = t->bound;
+       if(b == -100) {
+               // flag for [...]
+               b = ninit;
+               t = shallow(t);
+               t->bound = b;
+       }
+
        var = nod(OXXX, N, N);
        tempname(var, t);
 
-       b = t->bound;
-       if(b < 0 && b != -100) {
+       if(b < 0) {
                // slice
                nnew = nod(OMAKE, N, N);
                nnew->type = t;
 
                a = nod(OAS, var, nnew);
                addtop = list(addtop, a);
-       }
-
-       if(b >= 0) {
-               idx = 0;
-               r = listfirst(&saver, &n->left);
-               if(r != N && r->op == OEMPTY)
-                       r = N;
-               while(r != N) {
-                       // count initializers
-                       idx++;
-                       r = listnext(&saver);
-               }
+       } else {
                // if entire array isnt initialized,
                // then clear the array
-               if(idx < b) {
+               if(ninit < b) {
                        a = nod(OAS, var, N);
                        addtop = list(addtop, a);
                }
@@ -3606,11 +3612,6 @@ arraylit(Node *n)
                idx++;
                r = listnext(&saver);
        }
-       if(b == -100) {
-               // compiler counted closed array
-               b = idx;
-               t->bound = b;
-       }
        if(b < 0)
                nnew->left = nodintconst(idx);
        return var;