mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
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:
parent
4ffc799295
commit
833dae6d26
3 changed files with 19 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
14
test/fixedbugs/issue6403.go
Normal file
14
test/fixedbugs/issue6403.go
Normal 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"
|
Loading…
Reference in a new issue