blob: 7946a87502b7fb0a28c410ae4cc48bdabdff6e99 [file] [log] [blame]
Russ Coxe5124812009-01-08 18:06:06 -08001// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG method3
2
3// Copyright 2009 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// test that methods on slices work
8
9package main
10
Rob Pike325cf8e2010-03-24 16:46:53 -070011type T []int
12
Russ Coxe5124812009-01-08 18:06:06 -080013func (t T) Len() int { return len(t) }
14
Russ Cox839a6842009-01-20 14:40:40 -080015type I interface {
Russ Coxe5124812009-01-08 18:06:06 -080016 Len() int
17}
18
19func main() {
Rob Pike325cf8e2010-03-24 16:46:53 -070020 var t T = T{0, 1, 2, 3, 4}
21 var i I
22 i = t
Russ Coxe5124812009-01-08 18:06:06 -080023 if i.Len() != 5 {
Rob Pike325cf8e2010-03-24 16:46:53 -070024 println("i.Len", i.Len())
25 panic("fail")
Russ Cox0d668252009-12-18 17:24:58 -080026 }
27 if T.Len(t) != 5 {
Rob Pike325cf8e2010-03-24 16:46:53 -070028 println("T.Len", T.Len(t))
29 panic("fail")
Russ Cox0d668252009-12-18 17:24:58 -080030 }
31 if (*T).Len(&t) != 5 {
Rob Pike325cf8e2010-03-24 16:46:53 -070032 println("(*T).Len", (*T).Len(&t))
33 panic("fail")
Russ Coxe5124812009-01-08 18:06:06 -080034 }
35}