diff options
Diffstat (limited to 'test/interface')
-rw-r--r-- | test/interface/fake.go | 24 | ||||
-rw-r--r-- | test/interface/private.go | 32 | ||||
-rw-r--r-- | test/interface/private1.go | 18 |
3 files changed, 62 insertions, 12 deletions
diff --git a/test/interface/fake.go b/test/interface/fake.go index 5cf3be052..de8505d8d 100644 --- a/test/interface/fake.go +++ b/test/interface/fake.go @@ -46,34 +46,34 @@ func main() { x.t = add("abc", "def") x.u = 1 x.v = 2 - x.w = 1<<28 - x.x = 2<<28 + x.w = 1 << 28 + x.x = 2 << 28 x.y = 0x12345678 x.z = x.y // check mem and string v := reflect.NewValue(x) - i := v.(*reflect.StructValue).Field(0) - j := v.(*reflect.StructValue).Field(1) + i := v.Field(0) + j := v.Field(1) assert(i.Interface() == j.Interface()) - s := v.(*reflect.StructValue).Field(2) - t := v.(*reflect.StructValue).Field(3) + 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.(*reflect.StructValue).Field(4) - j = v.(*reflect.StructValue).Field(5) + i = v.Field(4) + j = v.Field(5) assert(i.Interface() != j.Interface()) - i = v.(*reflect.StructValue).Field(6) - j = v.(*reflect.StructValue).Field(7) + i = v.Field(6) + j = v.Field(7) assert(i.Interface() != j.Interface()) - i = v.(*reflect.StructValue).Field(8) - j = v.(*reflect.StructValue).Field(9) + i = v.Field(8) + j = v.Field(9) assert(i.Interface() == j.Interface()) } diff --git a/test/interface/private.go b/test/interface/private.go new file mode 100644 index 000000000..37890c923 --- /dev/null +++ b/test/interface/private.go @@ -0,0 +1,32 @@ +// $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 new file mode 100644 index 000000000..3173fbef4 --- /dev/null +++ b/test/interface/private1.go @@ -0,0 +1,18 @@ +// 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) + |