cmd/gc: reject builtin function calls in len(fixed array) constants

Fixes #7385.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/84010044
This commit is contained in:
Russ Cox 2014-04-03 19:04:33 -04:00
parent a26c01ad44
commit f3ecb298ad
2 changed files with 20 additions and 1 deletions

View file

@ -1629,10 +1629,25 @@ hascallchan(Node *n)
if(n == N)
return 0;
switch(n->op) {
case OAPPEND:
case OCALL:
case OCALLFUNC:
case OCALLMETH:
case OCALLINTER:
case OCALLMETH:
case OCAP:
case OCLOSE:
case OCOMPLEX:
case OCOPY:
case ODELETE:
case OIMAG:
case OLEN:
case OMAKE:
case ONEW:
case OPANIC:
case OPRINT:
case OPRINTN:
case OREAL:
case ORECOVER:
case ORECV:
return 1;
}

View file

@ -18,6 +18,7 @@ var s [][30]int
func f() *[40]int
var c chan *[50]int
var z complex128
const (
n1 = len(b.a)
@ -29,5 +30,8 @@ const (
n6 = cap(f()) // ERROR "is not a constant|is not constant"
n7 = cap(<-c) // ERROR "is not a constant|is not constant"
n8 = real(z) // ERROR "is not a constant|is not constant"
n9 = len([4]float64{real(z)}) // ERROR "is not a constant|is not constant"
)