Commit f3ecb298 authored by Russ Cox's avatar Russ Cox

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
parent a26c01ad
......@@ -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;
}
......
......@@ -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"
)
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