cmd/gc: fix spurious 'const initializer is not a constant' error

Fixes #6403

LGTM=rsc
R=iant, rsc
CC=golang-codereviews
https://golang.org/cl/72840044
This commit is contained in:
Jan Ziak 2014-03-24 20:36:42 +01:00
parent 4ffc799295
commit 833dae6d26
3 changed files with 19 additions and 1 deletions

View 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;

View 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;

View file

@ -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"