]> Cypherpunks.ru repositories - gostls13.git/commitdiff
gc: disallow [...][...]int{{1,2,3}}
authorRuss Cox <rsc@golang.org>
Tue, 26 Jul 2011 04:52:02 +0000 (00:52 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 26 Jul 2011 04:52:02 +0000 (00:52 -0400)
Fixes #1600.

R=ken2
CC=golang-dev
https://golang.org/cl/4819045

src/cmd/gc/go.h
src/cmd/gc/typecheck.c
test/ddd1.go

index ee4ee6c89ba99a4afb6551a51f17373247169654..f7d65976035228c7217236541551a4a5edd39fb4 100644 (file)
@@ -531,6 +531,7 @@ enum
        Eindir = 1<<8,          // indirecting through expression
        Eaddr = 1<<9,           // taking address of expression
        Eproc = 1<<10,          // inside a go statement
+       Ecomplit = 1<<11,       // type in composite literal
 };
 
 #define        BITS    5
index dfe0f30f7740dc1261772b1e1b7576b651f93e22..80af8201d8e5693e0067a971b81b2db17869f686 100644 (file)
@@ -239,6 +239,8 @@ reswitch:
                        t->bound = -1;  // slice
                } else if(l->op == ODDD) {
                        t->bound = -100;        // to be filled in
+                       if(!(top&Ecomplit))
+                               yyerror("use of [...] array outside of array literal");
                } else {
                        l = typecheck(&n->left, Erv);
                        switch(consttype(l)) {
@@ -1342,11 +1344,6 @@ ret:
                case TNIL:
                case TBLANK:
                        break;
-               case TARRAY:
-                       if(t->bound == -100) {
-                               yyerror("use of [...] array outside of array literal");
-                               t->bound = 1;
-                       }
                default:
                        checkwidth(t);
                }
@@ -1971,7 +1968,7 @@ typecheckcomplit(Node **np)
        }
 
        setlineno(n->right);
-       l = typecheck(&n->right /* sic */, Etype);
+       l = typecheck(&n->right /* sic */, Etype|Ecomplit);
        if((t = l->type) == T)
                goto error;
        nerr = nerrors;
@@ -2039,7 +2036,7 @@ typecheckcomplit(Node **np)
                                l->right->right = typenod(pushtype);
                        typecheck(&l->right, Erv);
                        defaultlit(&l->right, t->type);
-                       l->right = assignconv(l->right, t->type, "array index");
+                       l->right = assignconv(l->right, t->type, "array element");
                }
                if(t->bound == -100)
                        t->bound = len;
index 96a358e1c01f54bf6146f7e39d9835a8f43f3e86..83e32de7b6bce94830113427344aee4de164659f 100644 (file)
@@ -44,4 +44,6 @@ func bad(args ...int) {
        _ = unsafe.Pointer(&x...)       // ERROR "[.][.][.]"
        _ = unsafe.Sizeof(x...) // ERROR "[.][.][.]"
        _ = [...]byte("foo") // ERROR "[.][.][.]"
+       _ = [...][...]int{{1,2,3},{4,5,6}}      // ERROR "[.][.][.]"
 }
+