diff options
author | Russ Cox <rsc@golang.org> | 2011-12-02 14:13:12 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-12-02 14:13:12 -0500 |
commit | 7dc9d8c72b5deb927028e9edfbc6015c5d0296be (patch) | |
tree | 3fdff8e3142745f7e26f98395cdb87c8ac62974f /test | |
parent | 5f49456465f53f96bee03ac8cbe0d564e31576c2 (diff) | |
download | go-git-7dc9d8c72b5deb927028e9edfbc6015c5d0296be.tar.gz |
gc: composite literals as per Go 1
R=ken2
CC=golang-dev
https://golang.org/cl/5450067
Diffstat (limited to 'test')
-rw-r--r-- | test/complit.go | 16 | ||||
-rw-r--r-- | test/complit1.go | 27 |
2 files changed, 37 insertions, 6 deletions
diff --git a/test/complit.go b/test/complit.go index f5f7aca9d9..c9de616f55 100644 --- a/test/complit.go +++ b/test/complit.go @@ -31,6 +31,18 @@ func eq(a []*R) { } } +func teq(t *T, n int) { + for i := 0; i < n; i++ { + if t == nil || t.i != i { + panic("bad") + } + t = t.next + } + if t != nil { + panic("bad") + } +} + type P struct { a, b int } @@ -46,6 +58,9 @@ func main() { var tp *T tp = &T{0, 7.2, "hi", &t} + tl := &T{i: 0, next: {i: 1, next: {i: 2, next: {i: 3, next: {i: 4}}}}} + teq(tl, 5) + a1 := []int{1, 2, 3} if len(a1) != 3 { panic("a1") @@ -93,6 +108,7 @@ func main() { } eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)}) + eq([]*R{{0}, {1}, {2}, {3}, {4}, {5}}) p1 := NewP(1, 2) p2 := NewP(1, 2) diff --git a/test/complit1.go b/test/complit1.go index 23b3bbd192..f4f7311af3 100644 --- a/test/complit1.go +++ b/test/complit1.go @@ -7,18 +7,33 @@ package main var m map[int][3]int + func f() [3]int func fp() *[3]int + var mp map[int]*[3]int var ( - _ = [3]int{1,2,3}[:] // ERROR "slice of unaddressable value" - _ = m[0][:] // ERROR "slice of unaddressable value" - _ = f()[:] // ERROR "slice of unaddressable value" - + _ = [3]int{1, 2, 3}[:] // ERROR "slice of unaddressable value" + _ = m[0][:] // ERROR "slice of unaddressable value" + _ = f()[:] // ERROR "slice of unaddressable value" + // these are okay because they are slicing a pointer to an array - _ = (&[3]int{1,2,3})[:] + _ = (&[3]int{1, 2, 3})[:] _ = mp[0][:] _ = fp()[:] -)
\ No newline at end of file +) + +type T struct { + i int + f float64 + s string + next *T +} + +var ( + _ = &T{0, 0, "", nil} // ok + _ = &T{i: 0, f: 0, s: "", next: {}} // ok + _ = &T{0, 0, "", {}} // ERROR "missing type in composite literal" +) |