cmd/gc: say 'non-constant array bound' instead of 'invalid array bound'

Fixes #8196.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/141510044
This commit is contained in:
Russ Cox 2014-09-16 10:21:54 -04:00
parent 3d2321f639
commit 8d61334dd5
2 changed files with 16 additions and 8 deletions

View file

@ -408,7 +408,10 @@ reswitch:
v = toint(l->val);
break;
default:
yyerror("invalid array bound %N", l);
if(l->type != T && isint[l->type->etype] && l->op != OLITERAL)
yyerror("non-constant array bound %N", l);
else
yyerror("invalid array bound %N", l);
goto error;
}
t->bound = mpgetfix(v.u.xval);

View file

@ -6,10 +6,15 @@
package main
var a [10]int // ok
var b [1e1]int // ok
var c [1.5]int // ERROR "truncated"
var d ["abc"]int // ERROR "invalid array bound|not numeric"
var e [nil]int // ERROR "invalid array bound|not numeric"
var f [e]int // ERROR "invalid array bound|not constant"
var g [1<<65]int // ERROR "array bound is too large|overflows"
var a [10]int // ok
var b [1e1]int // ok
var c [1.5]int // ERROR "truncated"
var d ["abc"]int // ERROR "invalid array bound|not numeric"
var e [nil]int // ERROR "invalid array bound|not numeric"
var f [e]int // ERROR "invalid array bound|not constant"
var g [1 << 65]int // ERROR "array bound is too large|overflows"
var h [len(a)]int // ok
func ff() string
var i [len([1]string{ff()})]int // ERROR "non-constant array bound|not constant"