Commit 8d61334d authored by Russ Cox's avatar Russ Cox

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
parent 3d2321f6
...@@ -408,7 +408,10 @@ reswitch: ...@@ -408,7 +408,10 @@ reswitch:
v = toint(l->val); v = toint(l->val);
break; break;
default: 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; goto error;
} }
t->bound = mpgetfix(v.u.xval); t->bound = mpgetfix(v.u.xval);
......
...@@ -6,10 +6,15 @@ ...@@ -6,10 +6,15 @@
package main package main
var a [10]int // ok var a [10]int // ok
var b [1e1]int // ok var b [1e1]int // ok
var c [1.5]int // ERROR "truncated" var c [1.5]int // ERROR "truncated"
var d ["abc"]int // ERROR "invalid array bound|not numeric" var d ["abc"]int // ERROR "invalid array bound|not numeric"
var e [nil]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 f [e]int // ERROR "invalid array bound|not constant"
var g [1<<65]int // ERROR "array bound is too large|overflows" 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"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment