From 833dae6d26c56bde5fbae27fde0cdc6efa63fefa Mon Sep 17 00:00:00 2001 From: Jan Ziak <0xe2.0x9a.0x9b@gmail.com> Date: Mon, 24 Mar 2014 20:36:42 +0100 Subject: [PATCH] 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 --- src/cmd/gc/subr.c | 1 + src/cmd/gc/typecheck.c | 5 ++++- test/fixedbugs/issue6403.go | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue6403.go diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c index 01a5c435aa..f9746f0278 100644 --- a/src/cmd/gc/subr.c +++ b/src/cmd/gc/subr.c @@ -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; diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index ebff0694a0..f6e77acebd 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -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 index 0000000000..b61e2e225d --- /dev/null +++ b/test/fixedbugs/issue6403.go @@ -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" -- 2.50.0