]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix spurious 'const initializer is not a constant' error
authorJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Mon, 24 Mar 2014 19:36:42 +0000 (20:36 +0100)
committerJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Mon, 24 Mar 2014 19:36:42 +0000 (20:36 +0100)
Fixes #6403

LGTM=rsc
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/72840044

src/cmd/gc/subr.c
src/cmd/gc/typecheck.c
test/fixedbugs/issue6403.go [new file with mode: 0644]

index 01a5c435aabcb9fced0965d9f1128847f5fa8456..f9746f0278cb79ad7b19f7bdf8a0c073f69ec30a 100644 (file)
@@ -2243,6 +2243,7 @@ adddot(Node *n)
        int c, d;
 
        typecheck(&n->left, Etype|Erv);
+       n->diag |= n->left->diag;
        t = n->left->type;
        if(t == T)
                goto ret;
index ebff0694a0670e7bd6a6d4ab105354c83873d83a..f6e77acebdbc18abc39c47b9ee78928b4d3b2dcb 100644 (file)
@@ -3174,7 +3174,10 @@ typecheckdef(Node *n)
                        goto ret;
                }
                if(e->type != T && e->op != OLITERAL || !isgoconst(e)) {
-                       yyerror("const initializer %N is not a constant", e);
+                       if(!e->diag) {
+                               yyerror("const initializer %N is not a constant", e);
+                               e->diag = 1;
+                       }
                        goto ret;
                }
                t = n->type;
diff --git a/test/fixedbugs/issue6403.go b/test/fixedbugs/issue6403.go
new file mode 100644 (file)
index 0000000..b61e2e2
--- /dev/null
@@ -0,0 +1,14 @@
+// errorcheck
+
+// Copyright 2014 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.
+
+// Issue 6403: fix spurious 'const initializer is not a constant' error
+
+package p
+
+import "syscall"
+
+const A int = syscall.X // ERROR "undefined: syscall.X"
+const B int = voidpkg.X // ERROR "undefined: voidpkg"