aboutsummaryrefslogtreecommitdiff
path: root/test/const5.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-03-07 22:43:28 -0500
committerRuss Cox <rsc@golang.org>2012-03-07 22:43:28 -0500
commitd4fb568e047a23a5ade5c3750da0de9fb54ff33a (patch)
tree45787ad26bf87f51c13b727d8c13278f2c9f43d7 /test/const5.go
parent43d71e7d7d1ace38e6518335ff39b7848700b9ca (diff)
downloadgo-d4fb568e047a23a5ade5c3750da0de9fb54ff33a.tar.gz
go-d4fb568e047a23a5ade5c3750da0de9fb54ff33a.zip
cmd/gc: implement len(array) / cap(array) rule
The spec is looser than the current implementation. The spec edit was made in CL 4444050 (May 2011) but I never implemented it. Fixes #3244. R=ken2 CC=golang-dev https://golang.org/cl/5785049
Diffstat (limited to 'test/const5.go')
-rw-r--r--test/const5.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/const5.go b/test/const5.go
new file mode 100644
index 0000000000..8e0385e9a5
--- /dev/null
+++ b/test/const5.go
@@ -0,0 +1,33 @@
+// errorcheck
+
+// Copyright 2011 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.
+
+// Test that len non-constants are not constants, http://golang.org/issue/3244.
+
+package p
+
+var b struct {
+ a[10]int
+}
+
+var m map[string][20]int
+
+var s [][30]int
+
+func f() *[40]int
+var c chan *[50]int
+
+const (
+ n1 = len(b.a)
+ n2 = len(m[""])
+ n3 = len(s[10])
+
+ n4 = len(f()) // ERROR "must be constant"
+ n5 = len(<-c) // ERROR "must be constant"
+
+ n6 = cap(f()) // ERROR "must be constant"
+ n7 = cap(<-c) // ERROR "must be constant"
+)
+