]> Cypherpunks repositories - gostls13.git/commitdiff
constant keys for array initializers
authorRuss Cox <rsc@golang.org>
Tue, 28 Jul 2009 00:58:25 +0000 (17:58 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 28 Jul 2009 00:58:25 +0000 (17:58 -0700)
R=ken
OCL=32261
CL=32261

src/cmd/gc/sinit.c
src/cmd/gc/walk.c
test/fixedbugs/bug176.go [new file with mode: 0644]

index e0581e64ce77f877f79090a5747f31cc37130f67..e41d1158499bd7280a5b893fcb5317c29d1e4c0c 100644 (file)
@@ -458,6 +458,9 @@ initfix(NodeList *l)
 if(0)
 return xxx.list;
 
+       if(nerrors != 0)
+               return xxx.list;
+
        // look for the copy-out reference
        for(l=xxx.list; l; l=l->next) {
                r = l->n;
index 31b52434a3e7ee3cfb54ce7fc7fc673b4f0364af..a97ea72314c3667943af8bb56a8e9faad0bdda6c 100644 (file)
@@ -4534,7 +4534,7 @@ arraylit(Node *n, Node *var, NodeList **init)
                if(r->op == OKEY) {
                        b = nonnegconst(r->left);
                        if(b < 0) {
-                               yyerror("array index must be non-negative integer");
+                               yyerror("array index must be non-negative constant");
                                break;
                        }
                        r = r->right;
diff --git a/test/fixedbugs/bug176.go b/test/fixedbugs/bug176.go
new file mode 100644 (file)
index 0000000..5820df3
--- /dev/null
@@ -0,0 +1,14 @@
+// errchk $G $D/$F.go
+
+// Copyright 2009 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var x int
+
+var a = []int{ x: 1}   // ERROR "constant"
+var b = [...]int{ x : 1}       // ERROR "constant"
+var c = map[int]int{ x: 1}
+