diff options
Diffstat (limited to 'test/interface')
-rw-r--r-- | test/interface/bigdata.go | 75 | ||||
-rw-r--r-- | test/interface/convert.go | 147 | ||||
-rw-r--r-- | test/interface/convert1.go | 25 | ||||
-rw-r--r-- | test/interface/convert2.go | 25 | ||||
-rw-r--r-- | test/interface/embed.go | 61 | ||||
-rw-r--r-- | test/interface/embed0.go | 29 | ||||
-rw-r--r-- | test/interface/embed1.go | 45 | ||||
-rw-r--r-- | test/interface/embed2.go | 70 | ||||
-rw-r--r-- | test/interface/explicit.go | 75 | ||||
-rw-r--r-- | test/interface/fail.go | 26 | ||||
-rw-r--r-- | test/interface/fake.go | 97 | ||||
-rw-r--r-- | test/interface/pointer.go | 37 | ||||
-rw-r--r-- | test/interface/private.go | 32 | ||||
-rw-r--r-- | test/interface/private1.go | 18 | ||||
-rw-r--r-- | test/interface/receiver.go | 121 | ||||
-rw-r--r-- | test/interface/receiver1.go | 58 | ||||
-rw-r--r-- | test/interface/recursive.go | 21 | ||||
-rw-r--r-- | test/interface/returntype.go | 25 | ||||
-rw-r--r-- | test/interface/struct.go | 156 |
19 files changed, 0 insertions, 1143 deletions
diff --git a/test/interface/bigdata.go b/test/interface/bigdata.go deleted file mode 100644 index 44f6ab127..000000000 --- a/test/interface/bigdata.go +++ /dev/null @@ -1,75 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// check that big vs small, pointer vs not -// interface methods work. - -package main - -type I interface { M() int64 } - -type BigPtr struct { a, b, c, d int64 } -func (z *BigPtr) M() int64 { return z.a+z.b+z.c+z.d } - -type SmallPtr struct { a int32 } -func (z *SmallPtr) M() int64 { return int64(z.a) } - -type IntPtr int32 -func (z *IntPtr) M() int64 { return int64(*z) } - -var bad bool - -func test(name string, i I) { - m := i.M() - if m != 12345 { - println(name, m) - bad = true - } -} - -func ptrs() { - var bigptr BigPtr = BigPtr{ 10000, 2000, 300, 45 } - var smallptr SmallPtr = SmallPtr{ 12345 } - var intptr IntPtr = 12345 - -// test("bigptr", bigptr) - test("&bigptr", &bigptr) -// test("smallptr", smallptr) - test("&smallptr", &smallptr) -// test("intptr", intptr) - test("&intptr", &intptr) -} - -type Big struct { a, b, c, d int64 } -func (z Big) M() int64 { return z.a+z.b+z.c+z.d } - -type Small struct { a int32 } -func (z Small) M() int64 { return int64(z.a) } - -type Int int32 -func (z Int) M() int64 { return int64(z) } - -func nonptrs() { - var big Big = Big{ 10000, 2000, 300, 45 } - var small Small = Small{ 12345 } - var int Int = 12345 - - test("big", big) - test("&big", &big) - test("small", small) - test("&small", &small) - test("int", int) - test("&int", &int) -} - -func main() { - ptrs() - nonptrs() - - if bad { - println("BUG: interface4") - } -} diff --git a/test/interface/convert.go b/test/interface/convert.go deleted file mode 100644 index 7f429f703..000000000 --- a/test/interface/convert.go +++ /dev/null @@ -1,147 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// Check uses of all the different interface -// conversion runtime functions. - -package main - -type Stringer interface { - String() string -} -type StringLengther interface { - String() string - Length() int -} -type Empty interface{} - -type T string - -func (t T) String() string { - return string(t) -} -func (t T) Length() int { - return len(t) -} - -type U string - -func (u U) String() string { - return string(u) -} - -var t = T("hello") -var u = U("goodbye") -var e Empty -var s Stringer = t -var sl StringLengther = t -var i int -var ok bool - -func hello(s string) { - if s != "hello" { - println("not hello: ", s) - panic("fail") - } -} - -func five(i int) { - if i != 5 { - println("not 5: ", i) - panic("fail") - } -} - -func true(ok bool) { - if !ok { - panic("not true") - } -} - -func false(ok bool) { - if ok { - panic("not false") - } -} - -func main() { - // T2I - s = t - hello(s.String()) - - // I2T - t = s.(T) - hello(t.String()) - - // T2E - e = t - - // E2T - t = e.(T) - hello(t.String()) - - // T2I again - sl = t - hello(sl.String()) - five(sl.Length()) - - // I2I static - s = sl - hello(s.String()) - - // I2I dynamic - sl = s.(StringLengther) - hello(sl.String()) - five(sl.Length()) - - // I2E (and E2T) - e = s - hello(e.(T).String()) - - // E2I - s = e.(Stringer) - hello(s.String()) - - // I2T2 true - t, ok = s.(T) - true(ok) - hello(t.String()) - - // I2T2 false - _, ok = s.(U) - false(ok) - - // I2I2 true - sl, ok = s.(StringLengther) - true(ok) - hello(sl.String()) - five(sl.Length()) - - // I2I2 false (and T2I) - s = u - sl, ok = s.(StringLengther) - false(ok) - - // E2T2 true - t, ok = e.(T) - true(ok) - hello(t.String()) - - // E2T2 false - i, ok = e.(int) - false(ok) - - // E2I2 true - sl, ok = e.(StringLengther) - true(ok) - hello(sl.String()) - five(sl.Length()) - - // E2I2 false (and T2E) - e = u - sl, ok = e.(StringLengther) - false(ok) -} diff --git a/test/interface/convert1.go b/test/interface/convert1.go deleted file mode 100644 index 658b1a92f..000000000 --- a/test/interface/convert1.go +++ /dev/null @@ -1,25 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// Check that static interface conversion of -// interface value nil succeeds. - -package main - -type R interface { R() } -type RW interface { R(); W() } - -var e interface {} -var r R -var rw RW - -func main() { - r = r - r = rw - e = r - e = rw - rw = rw -} diff --git a/test/interface/convert2.go b/test/interface/convert2.go deleted file mode 100644 index 658b1a92f..000000000 --- a/test/interface/convert2.go +++ /dev/null @@ -1,25 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// Check that static interface conversion of -// interface value nil succeeds. - -package main - -type R interface { R() } -type RW interface { R(); W() } - -var e interface {} -var r R -var rw RW - -func main() { - r = r - r = rw - e = r - e = rw - rw = rw -} diff --git a/test/interface/embed.go b/test/interface/embed.go deleted file mode 100644 index 2fddee190..000000000 --- a/test/interface/embed.go +++ /dev/null @@ -1,61 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// Check methods derived from embedded interface values. - -package main - -import "os" - -const Value = 1e12 - -type Inter interface { M() int64 } - -type T int64 -func (t T) M() int64 { return int64(t) } -var t = T(Value) -var pt = &t -var ti Inter = t - -type S struct { Inter } -var s = S{ ti } -var ps = &s - -var i Inter - -var ok = true - -func check(s string, v int64) { - if v != Value { - println(s, v) - ok = false - } -} - -func main() { - check("t.M()", t.M()) - check("pt.M()", pt.M()) - check("ti.M()", ti.M()) - check("s.M()", s.M()) - check("ps.M()", ps.M()) - - i = t - check("i = t; i.M()", i.M()) - - i = pt - check("i = pt; i.M()", i.M()) - - i = s - check("i = s; i.M()", i.M()) - - i = ps - check("i = ps; i.M()", i.M()) - - if !ok { - println("BUG: interface10") - os.Exit(1) - } -} diff --git a/test/interface/embed0.go b/test/interface/embed0.go deleted file mode 100644 index bbd81e760..000000000 --- a/test/interface/embed0.go +++ /dev/null @@ -1,29 +0,0 @@ -// true # used by embed1.go - -// Copyright 2009 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. - -// Check that embedded interface types can have local methods. - -package p - -type T int -func (t T) m() {} - -type I interface { m() } -type J interface { I } - -func main() { - var i I - var j J - var t T - i = t - j = t - _ = i - _ = j - i = j - _ = i - j = i - _ = j -} diff --git a/test/interface/embed1.go b/test/interface/embed1.go deleted file mode 100644 index 24e50471f..000000000 --- a/test/interface/embed1.go +++ /dev/null @@ -1,45 +0,0 @@ -// $G $D/embed0.go && $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// Check that embedded interface types can have local methods. - -package main - -import "./embed0" - -type T int -func (t T) m() {} - -type I interface { m() } -type J interface { I } - -type PI interface { p.I } -type PJ interface { p.J } - -func main() { - var i I - var j J - var t T - i = t - j = t - _ = i - _ = j - i = j - _ = i - j = i - _ = j - var pi PI - var pj PJ - var pt p.T - pi = pt - pj = pt - _ = pi - _ = pj - pi = pj - _ = pi - pj = pi - _ = pj -} diff --git a/test/interface/embed2.go b/test/interface/embed2.go deleted file mode 100644 index c18a1fece..000000000 --- a/test/interface/embed2.go +++ /dev/null @@ -1,70 +0,0 @@ -// errchk $G -e $D/$F.go - -// Copyright 2009 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. - -// Check methods derived from embedded interface and *interface values. - -package main - -import "os" - -const Value = 1e12 - -type Inter interface { M() int64 } - -type T int64 -func (t T) M() int64 { return int64(t) } -var t = T(Value) -var pt = &t -var ti Inter = t -var pti = &ti - -type S struct { Inter } -var s = S{ ti } -var ps = &s - -type SP struct { *Inter } // ERROR "interface" - -var i Inter -var pi = &i - -var ok = true - -func check(s string, v int64) { - if v != Value { - println(s, v) - ok = false - } -} - -func main() { - check("t.M()", t.M()) - check("pt.M()", pt.M()) - check("ti.M()", ti.M()) - check("pti.M()", pti.M()) // ERROR "method" - check("s.M()", s.M()) - check("ps.M()", ps.M()) - - i = t - check("i = t; i.M()", i.M()) - check("i = t; pi.M()", pi.M()) // ERROR "method" - - i = pt - check("i = pt; i.M()", i.M()) - check("i = pt; pi.M()", pi.M()) // ERROR "method" - - i = s - check("i = s; i.M()", i.M()) - check("i = s; pi.M()", pi.M()) // ERROR "method" - - i = ps - check("i = ps; i.M()", i.M()) - check("i = ps; pi.M()", pi.M()) // ERROR "method" - - if !ok { - println("BUG: interface10") - os.Exit(1) - } -} diff --git a/test/interface/explicit.go b/test/interface/explicit.go deleted file mode 100644 index b6a582fff..000000000 --- a/test/interface/explicit.go +++ /dev/null @@ -1,75 +0,0 @@ -// errchk $G -e $D/$F.go - -// Copyright 2009 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. - -// Static error messages about interface conversions. - -package main - -type T struct { - a int -} - -var t *T - -type I interface { - M() -} - -var i I - -type I2 interface { - M() - N() -} - -var i2 I2 - -type E interface{} - -var e E - -func main() { - e = t // ok - t = e // ERROR "need explicit|need type assertion" - - // neither of these can work, - // because i has an extra method - // that t does not, so i cannot contain a t. - i = t // ERROR "incompatible|missing M method" - t = i // ERROR "incompatible|need type assertion" - - i = i2 // ok - i2 = i // ERROR "incompatible|missing N method" - - i = I(i2) // ok - i2 = I2(i) // ERROR "invalid|missing N method" - - e = E(t) // ok - t = T(e) // ERROR "need explicit|need type assertion|incompatible" -} - -type M interface { - M() -} - -var m M - -var _ = m.(int) // ERROR "impossible type assertion" - -type Int int - -func (Int) M(float64) {} - -var _ = m.(Int) // ERROR "impossible type assertion" - -var ii int -var jj Int - -var m1 M = ii // ERROR "incompatible|missing" -var m2 M = jj // ERROR "incompatible|wrong type for M method" - -var m3 = M(ii) // ERROR "invalid|missing" -var m4 = M(jj) // ERROR "invalid|wrong type for M method" diff --git a/test/interface/fail.go b/test/interface/fail.go deleted file mode 100644 index 3e741d3f9..000000000 --- a/test/interface/fail.go +++ /dev/null @@ -1,26 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ! ./$A.out - -// Copyright 2009 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. - -// Check that interface conversion fails when method is missing. - -package main - -type I interface { - Foo() -} - -func main() { - var s *S - var i I - var e interface {} - e = s - i = e.(I) - _ = i -} - -// hide S down here to avoid static warning -type S struct { -} diff --git a/test/interface/fake.go b/test/interface/fake.go deleted file mode 100644 index bdc5b9072..000000000 --- a/test/interface/fake.go +++ /dev/null @@ -1,97 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// Interface comparisons using types hidden -// inside reflected-on structs. - -package main - -import "reflect" - -type T struct { - f float32 - g float32 - - s string - t string - - u uint32 - v uint32 - - w uint32 - x uint32 - - y uint32 - z uint32 -} - -func add(s, t string) string { - return s + t -} - -func assert(b bool) { - if !b { - panic("assert") - } -} - -func main() { - var x T - x.f = 1.0 - x.g = x.f - x.s = add("abc", "def") - x.t = add("abc", "def") - x.u = 1 - x.v = 2 - x.w = 1 << 28 - x.x = 2 << 28 - x.y = 0x12345678 - x.z = x.y - - // check mem and string - v := reflect.ValueOf(x) - i := v.Field(0) - j := v.Field(1) - assert(i.Interface() == j.Interface()) - - s := v.Field(2) - t := v.Field(3) - assert(s.Interface() == t.Interface()) - - // make sure different values are different. - // make sure whole word is being compared, - // not just a single byte. - i = v.Field(4) - j = v.Field(5) - assert(i.Interface() != j.Interface()) - - i = v.Field(6) - j = v.Field(7) - assert(i.Interface() != j.Interface()) - - i = v.Field(8) - j = v.Field(9) - assert(i.Interface() == j.Interface()) -} - -/* -comparing uncomparable type float32 -throw: interface compare - -panic PC=0x28ceb8 [1] -throw+0x41 /Users/rsc/goX/src/runtime/runtime.c:54 - throw(0x3014a, 0x0) -ifaceeq+0x15c /Users/rsc/goX/src/runtime/iface.c:501 - ifaceeq(0x2aa7c0, 0x0, 0x0, 0x0, 0x2aa7c0, ...) -sys·ifaceeq+0x48 /Users/rsc/goX/src/runtime/iface.c:527 - sys·ifaceeq(0x2aa7c0, 0x0, 0x0, 0x0, 0x2aa7c0, ...) -main·main+0x190 /Users/rsc/goX/src/cmd/gc/x.go:10 - main·main() -mainstart+0xf /Users/rsc/goX/src/runtime/amd64/asm.s:53 - mainstart() -sys·Goexit /Users/rsc/goX/src/runtime/proc.c:124 - sys·Goexit() -*/ diff --git a/test/interface/pointer.go b/test/interface/pointer.go deleted file mode 100644 index 076469c8d..000000000 --- a/test/interface/pointer.go +++ /dev/null @@ -1,37 +0,0 @@ -// errchk $G $D/$F.go - -// Copyright 2009 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. - -// Check that interface{M()} = *interface{M()} produces a compiler error. - -package main - -type Inst interface { - Next() *Inst -} - -type Regexp struct { - code []Inst - start Inst -} - -type Start struct { - foo *Inst -} - -func (start *Start) Next() *Inst { return nil } - - -func AddInst(Inst) *Inst { - print("ok in addinst\n") - return nil -} - -func main() { - print("call addinst\n") - var x Inst = AddInst(new(Start)) // ERROR "pointer to interface" - print("return from addinst\n") - var x *Inst = new(Start) // ERROR "pointer to interface" -} diff --git a/test/interface/private.go b/test/interface/private.go deleted file mode 100644 index 37890c923..000000000 --- a/test/interface/private.go +++ /dev/null @@ -1,32 +0,0 @@ -// $G $D/${F}1.go && errchk $G $D/$F.go - -// 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. - -package main - -import "./private1" - -type Exported interface { - private() -} - -type Implementation struct{} - -func (p *Implementation) private() {} - -func main() { - var x Exported - x = new(Implementation) - x.private() - - var px p.Exported - px = p.X - - px.private() // ERROR "private" - - px = new(Implementation) // ERROR "private" - - x = px // ERROR "private" -} diff --git a/test/interface/private1.go b/test/interface/private1.go deleted file mode 100644 index 3173fbef4..000000000 --- a/test/interface/private1.go +++ /dev/null @@ -1,18 +0,0 @@ -// true # used by private.go - -// 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. - -package p - -type Exported interface { - private() -} - -type Implementation struct{} - -func (p *Implementation) private() {} - -var X = new(Implementation) - diff --git a/test/interface/receiver.go b/test/interface/receiver.go deleted file mode 100644 index f53daf8da..000000000 --- a/test/interface/receiver.go +++ /dev/null @@ -1,121 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out - -// Copyright 2009 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. - -// Implicit methods for embedded types. -// Mixed pointer and non-pointer receivers. - -package main - -type T int - -var nv, np int - -func (t T) V() { - if t != 42 { - panic(t) - } - nv++ -} - -func (t *T) P() { - if *t != 42 { - println(t, *t) - panic("fail") - } - np++ -} - -type V interface { - V() -} -type P interface { - P() - V() -} - -type S struct { - T -} - -type SP struct { - *T -} - -func main() { - var t T - var v V - var p P - - t = 42 - - t.P() - t.V() - - v = t - v.V() - - p = &t - p.P() - p.V() - - v = &t - v.V() - - // p = t // ERROR - var i interface{} = t - if _, ok := i.(P); ok { - println("dynamic i.(P) succeeded incorrectly") - panic("fail") - } - - // println("--struct--"); - var s S - s.T = 42 - s.P() - s.V() - - v = s - s.V() - - p = &s - p.P() - p.V() - - v = &s - v.V() - - // p = s // ERROR - var j interface{} = s - if _, ok := j.(P); ok { - println("dynamic j.(P) succeeded incorrectly") - panic("fail") - } - - // println("--struct pointer--"); - var sp SP - sp.T = &t - sp.P() - sp.V() - - v = sp - sp.V() - - p = &sp - p.P() - p.V() - - v = &sp - v.V() - - p = sp // not error - p.P() - p.V() - - if nv != 13 || np != 7 { - println("bad count", nv, np) - panic("fail") - } -} diff --git a/test/interface/receiver1.go b/test/interface/receiver1.go deleted file mode 100644 index 51312d000..000000000 --- a/test/interface/receiver1.go +++ /dev/null @@ -1,58 +0,0 @@ -// errchk $G $D/$F.go - -// Copyright 2009 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. - -// Error messages about missing implicit methods. - -package main - -type T int - -func (t T) V() -func (t *T) P() - -type V interface { - V() -} -type P interface { - P() - V() -} - -type S struct { - T -} -type SP struct { - *T -} - -func main() { - var t T - var v V - var p P - var s S - var sp SP - - v = t - p = t // ERROR "does not implement|requires a pointer" - _, _ = v, p - v = &t - p = &t - _, _ = v, p - - v = s - p = s // ERROR "does not implement|requires a pointer" - _, _ = v, p - v = &s - p = &s - _, _ = v, p - - v = sp - p = sp // no error! - _, _ = v, p - v = &sp - p = &sp - _, _ = v, p -} diff --git a/test/interface/recursive.go b/test/interface/recursive.go deleted file mode 100644 index 1eb56e976..000000000 --- a/test/interface/recursive.go +++ /dev/null @@ -1,21 +0,0 @@ -// $G $D/$F.go || echo BUG: should compile - -// Copyright 2009 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. - -// Check mutually recursive interfaces - -package main - -type I1 interface { - foo() I2 -} - -type I2 interface { - bar() I1 -} - -type T int -func (t T) foo() I2 { return t } -func (t T) bar() I1 { return t } diff --git a/test/interface/returntype.go b/test/interface/returntype.go deleted file mode 100644 index c526b3b0e..000000000 --- a/test/interface/returntype.go +++ /dev/null @@ -1,25 +0,0 @@ -// $G $D/$F.go && $L $F.$A && (! ./$A.out || echo BUG: should not succeed) - -// Copyright 2009 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. - -// Check methods with different return types. - -package main - -type S struct { a int } -type T struct { b string } - -func (s *S) Name() int8 { return 1 } -func (t *T) Name() int64 { return 64 } - -type I1 interface { Name() int8 } -type I2 interface { Name() int64 } - -func main() { - var i1 I1 - var s *S - i1 = s - print(i1.(I2).Name()) -} diff --git a/test/interface/struct.go b/test/interface/struct.go deleted file mode 100644 index 40b7f4f91..000000000 --- a/test/interface/struct.go +++ /dev/null @@ -1,156 +0,0 @@ -// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG interface6 - -// Copyright 2009 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. - -// Interface values containing structures. - -package main - -import "os" - -var fail int - -func check(b bool, msg string) { - if (!b) { - println("failure in", msg) - fail++ - } -} - -type I1 interface { Get() int; Put(int) } - -type S1 struct { i int } -func (p S1) Get() int { return p.i } -func (p S1) Put(i int) { p.i = i } - -func f1() { - s := S1{1} - var i I1 = s - i.Put(2) - check(i.Get() == 1, "f1 i") - check(s.i == 1, "f1 s") -} - -func f2() { - s := S1{1} - var i I1 = &s - i.Put(2) - check(i.Get() == 1, "f2 i") - check(s.i == 1, "f2 s") -} - -func f3() { - s := &S1{1} - var i I1 = s - i.Put(2) - check(i.Get() == 1, "f3 i") - check(s.i == 1, "f3 s") -} - -type S2 struct { i int } -func (p *S2) Get() int { return p.i } -func (p *S2) Put(i int) { p.i = i } - -// Disallowed by restriction of values going to pointer receivers -// func f4() { -// s := S2{1} -// var i I1 = s -// i.Put(2) -// check(i.Get() == 2, "f4 i") -// check(s.i == 1, "f4 s") -// } - -func f5() { - s := S2{1} - var i I1 = &s - i.Put(2) - check(i.Get() == 2, "f5 i") - check(s.i == 2, "f5 s") -} - -func f6() { - s := &S2{1} - var i I1 = s - i.Put(2) - check(i.Get() == 2, "f6 i") - check(s.i == 2, "f6 s") -} - -type I2 interface { Get() int64; Put(int64) } - -type S3 struct { i, j, k, l int64 } -func (p S3) Get() int64 { return p.l } -func (p S3) Put(i int64) { p.l = i } - -func f7() { - s := S3{1, 2, 3, 4} - var i I2 = s - i.Put(5) - check(i.Get() == 4, "f7 i") - check(s.l == 4, "f7 s") -} - -func f8() { - s := S3{1, 2, 3, 4} - var i I2 = &s - i.Put(5) - check(i.Get() == 4, "f8 i") - check(s.l == 4, "f8 s") -} - -func f9() { - s := &S3{1, 2, 3, 4} - var i I2 = s - i.Put(5) - check(i.Get() == 4, "f9 i") - check(s.l == 4, "f9 s") -} - -type S4 struct { i, j, k, l int64 } -func (p *S4) Get() int64 { return p.l } -func (p *S4) Put(i int64) { p.l = i } - -// Disallowed by restriction of values going to pointer receivers -// func f10() { -// s := S4{1, 2, 3, 4} -// var i I2 = s -// i.Put(5) -// check(i.Get() == 5, "f10 i") -// check(s.l == 4, "f10 s") -// } - -func f11() { - s := S4{1, 2, 3, 4} - var i I2 = &s - i.Put(5) - check(i.Get() == 5, "f11 i") - check(s.l == 5, "f11 s") -} - -func f12() { - s := &S4{1, 2, 3, 4} - var i I2 = s - i.Put(5) - check(i.Get() == 5, "f12 i") - check(s.l == 5, "f12 s") -} - -func main() { - f1() - f2() - f3() -// f4() - f5() - f6() - f7() - f8() - f9() -// f10() - f11() - f12() - if fail > 0 { - os.Exit(1) - } -} |