diff options
Diffstat (limited to 'gcc/testsuite/go.test/test/interface')
-rw-r--r-- | gcc/testsuite/go.test/test/interface/embed.go | 23 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/embed2.go | 70 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/explicit.go | 2 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/fail.go | 16 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/fake.go | 62 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/noeq.go | 39 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/pointer.go | 1 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/private.go | 32 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/private1.go | 18 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/recursive1.go | 15 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/recursive2.go | 22 | ||||
-rw-r--r-- | gcc/testsuite/go.test/test/interface/returntype.go | 15 |
12 files changed, 258 insertions, 57 deletions
diff --git a/gcc/testsuite/go.test/test/interface/embed.go b/gcc/testsuite/go.test/test/interface/embed.go index 4a702398c6..2fddee1905 100644 --- a/gcc/testsuite/go.test/test/interface/embed.go +++ b/gcc/testsuite/go.test/test/interface/embed.go @@ -4,7 +4,7 @@ // 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. +// Check methods derived from embedded interface values. package main @@ -19,18 +19,12 @@ 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 } -var sp = SP{ &ti } -var psp = &sp - var i Inter -var pi = &i var ok = true @@ -45,35 +39,20 @@ func main() { check("t.M()", t.M()) check("pt.M()", pt.M()) check("ti.M()", ti.M()) - check("pti.M()", pti.M()) check("s.M()", s.M()) check("ps.M()", ps.M()) - check("sp.M()", sp.M()) - check("psp.M()", psp.M()) i = t check("i = t; i.M()", i.M()) - check("i = t; pi.M()", pi.M()) i = pt check("i = pt; i.M()", i.M()) - check("i = pt; pi.M()", pi.M()) i = s check("i = s; i.M()", i.M()) - check("i = s; pi.M()", pi.M()) i = ps check("i = ps; i.M()", i.M()) - check("i = ps; pi.M()", pi.M()) - - i = sp - check("i = sp; i.M()", i.M()) - check("i = sp; pi.M()", pi.M()) - - i = psp - check("i = psp; i.M()", i.M()) - check("i = psp; pi.M()", pi.M()) if !ok { println("BUG: interface10") diff --git a/gcc/testsuite/go.test/test/interface/embed2.go b/gcc/testsuite/go.test/test/interface/embed2.go new file mode 100644 index 0000000000..c18a1fecec --- /dev/null +++ b/gcc/testsuite/go.test/test/interface/embed2.go @@ -0,0 +1,70 @@ +// 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/gcc/testsuite/go.test/test/interface/explicit.go b/gcc/testsuite/go.test/test/interface/explicit.go index b6a582fffb..daae59b361 100644 --- a/gcc/testsuite/go.test/test/interface/explicit.go +++ b/gcc/testsuite/go.test/test/interface/explicit.go @@ -48,7 +48,7 @@ func main() { i2 = I2(i) // ERROR "invalid|missing N method" e = E(t) // ok - t = T(e) // ERROR "need explicit|need type assertion|incompatible" + t = T(e) // ERROR "need explicit|need type assertion|incompatible" "as type [*]T" } type M interface { diff --git a/gcc/testsuite/go.test/test/interface/fail.go b/gcc/testsuite/go.test/test/interface/fail.go index 3e741d3f91..0c20bcf756 100644 --- a/gcc/testsuite/go.test/test/interface/fail.go +++ b/gcc/testsuite/go.test/test/interface/fail.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.$A && ! ./$A.out +// $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 @@ -13,6 +13,10 @@ type I interface { } func main() { + shouldPanic(p1) +} + +func p1() { var s *S var i I var e interface {} @@ -21,6 +25,14 @@ func main() { _ = i } -// hide S down here to avoid static warning type S struct { } + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} diff --git a/gcc/testsuite/go.test/test/interface/fake.go b/gcc/testsuite/go.test/test/interface/fake.go index 5cf3be052c..ddb8325427 100644 --- a/gcc/testsuite/go.test/test/interface/fake.go +++ b/gcc/testsuite/go.test/test/interface/fake.go @@ -12,20 +12,20 @@ package main import "reflect" type T struct { - f float32 - g float32 + F float32 + G float32 - s string - t string + S string + T string - u uint32 - v uint32 + U uint32 + V uint32 - w uint32 - x uint32 + W uint32 + X uint32 - y uint32 - z uint32 + Y uint32 + Z uint32 } func add(s, t string) string { @@ -40,40 +40,40 @@ func assert(b bool) { 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 + 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.NewValue(x) - i := v.(*reflect.StructValue).Field(0) - j := v.(*reflect.StructValue).Field(1) + v := reflect.ValueOf(x) + 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/gcc/testsuite/go.test/test/interface/noeq.go b/gcc/testsuite/go.test/test/interface/noeq.go new file mode 100644 index 0000000000..3c2ea5975a --- /dev/null +++ b/gcc/testsuite/go.test/test/interface/noeq.go @@ -0,0 +1,39 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: interface/noeq + +// 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. + +// Interface values containing types that cannot be compared for equality. + +package main + +func main() { + cmp(1) + + var ( + m map[int]int + s struct{ x []int } + f func() + ) + noCmp(m) + noCmp(s) + noCmp(f) +} + +func cmp(x interface{}) bool { + return x == x +} + +func noCmp(x interface{}) { + shouldPanic(func() { cmp(x) }) +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} diff --git a/gcc/testsuite/go.test/test/interface/pointer.go b/gcc/testsuite/go.test/test/interface/pointer.go index e628b558ea..f1e363cbff 100644 --- a/gcc/testsuite/go.test/test/interface/pointer.go +++ b/gcc/testsuite/go.test/test/interface/pointer.go @@ -33,4 +33,5 @@ func main() { print("call addinst\n") var x Inst = AddInst(new(Start)) // ERROR "pointer to interface" print("return from addinst\n") + var y *Inst = new(Start) // ERROR "pointer to interface|incompatible type" } diff --git a/gcc/testsuite/go.test/test/interface/private.go b/gcc/testsuite/go.test/test/interface/private.go new file mode 100644 index 0000000000..37890c923a --- /dev/null +++ b/gcc/testsuite/go.test/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/gcc/testsuite/go.test/test/interface/private1.go b/gcc/testsuite/go.test/test/interface/private1.go new file mode 100644 index 0000000000..3173fbef41 --- /dev/null +++ b/gcc/testsuite/go.test/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) + diff --git a/gcc/testsuite/go.test/test/interface/recursive1.go b/gcc/testsuite/go.test/test/interface/recursive1.go new file mode 100644 index 0000000000..2c93a28363 --- /dev/null +++ b/gcc/testsuite/go.test/test/interface/recursive1.go @@ -0,0 +1,15 @@ +// true # used by recursive2 + +// Copyright 2012 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 I1 interface { + F() I2 +} + +type I2 interface { + I1 +} diff --git a/gcc/testsuite/go.test/test/interface/recursive2.go b/gcc/testsuite/go.test/test/interface/recursive2.go new file mode 100644 index 0000000000..a7f9ab5dbd --- /dev/null +++ b/gcc/testsuite/go.test/test/interface/recursive2.go @@ -0,0 +1,22 @@ +// $G $D/recursive1.go && $G $D/$F.go + +// Copyright 2012 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 the mutually recursive types in recursive1.go made it +// intact and with the same meaning, by assigning to or using them. + +package main + +import "./recursive1" + +func main() { + var i1 p.I1 + var i2 p.I2 + i1 = i2 + i2 = i1 + i1 = i2.F() + i2 = i1.F() + _, _ = i1, i2 +} diff --git a/gcc/testsuite/go.test/test/interface/returntype.go b/gcc/testsuite/go.test/test/interface/returntype.go index c526b3b0ec..5cf0836178 100644 --- a/gcc/testsuite/go.test/test/interface/returntype.go +++ b/gcc/testsuite/go.test/test/interface/returntype.go @@ -1,4 +1,4 @@ -// $G $D/$F.go && $L $F.$A && (! ./$A.out || echo BUG: should not succeed) +// $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 @@ -18,8 +18,21 @@ type I1 interface { Name() int8 } type I2 interface { Name() int64 } func main() { + shouldPanic(p1) +} + +func p1() { var i1 I1 var s *S i1 = s print(i1.(I2).Name()) } + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} |