]> Cypherpunks repositories - gostls13.git/commitdiff
package main
authorRuss Cox <rsc@golang.org>
Thu, 25 Jun 2009 23:42:08 +0000 (16:42 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 25 Jun 2009 23:42:08 +0000 (16:42 -0700)
const foo = []int{1,2}

x.go:3: expression must be a constant

instead of

x.go:3: fatal error: gettype: addtop

R=ken
OCL=30767
CL=30767

src/cmd/gc/dcl.c

index 471319d0d924d497645c26b3a05c07c1f93c43ad..c33ead564da7d8501f1e417eb57f3921cb3121f8 100644 (file)
@@ -1684,7 +1684,7 @@ void
 constiter(Node *vv, Type *t, Node *cc)
 {
        Iter viter, citer;
-       Node *v, *c;
+       Node *v, *c, n1;
 
        if(cc == N) {
                if(t != T)
@@ -1712,7 +1712,16 @@ loop:
                return;
        }
 
-       gettype(c, N);
+       memset(&n1, 0, sizeof n1);
+       gettype(c, &n1);
+       if(n1.ninit != nil) {
+               // the expression had extra code to run.
+               // dodclconst is going to print an error
+               // because the expression isn't constant,
+               // but out of paranoia, bump nerrors so
+               // that compile cannot succeed accidentally
+               nerrors++;
+       }
        if(t != T)
                convlit(c, t);
        if(t == T)