aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/go.test/test/interface
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/gcc/testsuite/go.test/test/interface')
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/bigdata.go74
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/convert.go146
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/convert1.go24
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/convert2.go24
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/embed.go61
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed0.go27
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed1.go43
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.go9
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/embed2.go70
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/explicit.go101
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/fail.go53
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/fake.go97
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/noeq.go40
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/pointer.go38
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/private1.go18
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/prog.go33
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/private.go10
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/receiver.go121
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/receiver1.go59
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/recursive.go21
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive1.go15
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive2.go20
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.go9
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/returntype.go38
-rw-r--r--gcc-4.9/gcc/testsuite/go.test/test/interface/struct.go156
25 files changed, 1307 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/bigdata.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/bigdata.go
new file mode 100644
index 000000000..0f2e9a990
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/bigdata.go
@@ -0,0 +1,74 @@
+// run
+
+// 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.
+
+// Test big vs. small, pointer vs. value interface methods.
+
+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/gcc-4.9/gcc/testsuite/go.test/test/interface/convert.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/convert.go
new file mode 100644
index 000000000..eb6fd1d55
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/convert.go
@@ -0,0 +1,146 @@
+// run
+
+// 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.
+
+// Test 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/gcc-4.9/gcc/testsuite/go.test/test/interface/convert1.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/convert1.go
new file mode 100644
index 000000000..4a3ec8a37
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/convert1.go
@@ -0,0 +1,24 @@
+// run
+
+// 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.
+
+// Test static interface conversion of interface value nil.
+
+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/gcc-4.9/gcc/testsuite/go.test/test/interface/convert2.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/convert2.go
new file mode 100644
index 000000000..4a3ec8a37
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/convert2.go
@@ -0,0 +1,24 @@
+// run
+
+// 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.
+
+// Test static interface conversion of interface value nil.
+
+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/gcc-4.9/gcc/testsuite/go.test/test/interface/embed.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed.go
new file mode 100644
index 000000000..5c52ac023
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed.go
@@ -0,0 +1,61 @@
+// run
+
+// 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.
+
+// Test 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/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed0.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed0.go
new file mode 100644
index 000000000..728bec74e
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed0.go
@@ -0,0 +1,27 @@
+// 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.
+
+// Test 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/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed1.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed1.go
new file mode 100644
index 000000000..7dfb1dbc0
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.dir/embed1.go
@@ -0,0 +1,43 @@
+// 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.
+
+// Test 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/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.go
new file mode 100644
index 000000000..784b82bb0
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed1.go
@@ -0,0 +1,9 @@
+// rundir
+
+// 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.
+
+// Test that embedded interface types can have local methods.
+
+package ignored
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/embed2.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed2.go
new file mode 100644
index 000000000..1636db78e
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/embed2.go
@@ -0,0 +1,70 @@
+// errorcheck
+
+// 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.
+
+// Test 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-4.9/gcc/testsuite/go.test/test/interface/explicit.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/explicit.go
new file mode 100644
index 000000000..36fa1a422
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/explicit.go
@@ -0,0 +1,101 @@
+// errorcheck
+
+// 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.
+
+// Verify compiler messages about erroneous static interface conversions.
+// Does not compile.
+
+package main
+
+type T struct {
+ a int
+}
+
+var t *T
+
+type X int
+
+func (x *X) M() {}
+
+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|assignment$"
+
+ 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" "as type [*]T"
+}
+
+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 _ = m.(X) // ERROR "pointer receiver"
+
+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"
+
+
+type B1 interface {
+ _()
+}
+
+type B2 interface {
+ M()
+ _()
+}
+
+type T2 struct{}
+
+func (t *T2) M() {}
+func (t *T2) _() {}
+
+// Check that nothing satisfies an interface with blank methods.
+var b1 B1 = &T2{} // ERROR "incompatible|missing _ method"
+var b2 B2 = &T2{} // ERROR "incompatible|missing _ method"
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/fail.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/fail.go
new file mode 100644
index 000000000..81eb6cb3c
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/fail.go
@@ -0,0 +1,53 @@
+// run
+
+// 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.
+
+// Test that interface conversion fails when method is missing.
+
+package main
+
+type I interface {
+ Foo()
+}
+
+func main() {
+ shouldPanic(p1)
+ shouldPanic(p2)
+}
+
+func p1() {
+ var s *S
+ var i I
+ var e interface{}
+ e = s
+ i = e.(I)
+ _ = i
+}
+
+type S struct{}
+
+func (s *S) _() {}
+
+type B interface {
+ _()
+}
+
+func p2() {
+ var s *S
+ var b B
+ var e interface{}
+ e = s
+ b = e.(B)
+ _ = b
+}
+
+func shouldPanic(f func()) {
+ defer func() {
+ if recover() == nil {
+ panic("function should panic")
+ }
+ }()
+ f()
+}
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/fake.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/fake.go
new file mode 100644
index 000000000..861a64084
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/fake.go
@@ -0,0 +1,97 @@
+// run
+
+// 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.
+
+// Test 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/gcc-4.9/gcc/testsuite/go.test/test/interface/noeq.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/noeq.go
new file mode 100644
index 000000000..1c5166ede
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/noeq.go
@@ -0,0 +1,40 @@
+// run
+
+// 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.
+
+// Test run-time error detection for 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-4.9/gcc/testsuite/go.test/test/interface/pointer.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/pointer.go
new file mode 100644
index 000000000..292705066
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/pointer.go
@@ -0,0 +1,38 @@
+// errorcheck
+
+// 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.
+
+// Test that interface{M()} = *interface{M()} produces a compiler error.
+// Does not compile.
+
+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 y *Inst = new(Start) // ERROR "pointer to interface|incompatible type"
+}
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/private1.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/private1.go
new file mode 100644
index 000000000..75eee51f5
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/private1.go
@@ -0,0 +1,18 @@
+// 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.
+
+// Imported by private.go, which should not be able to see the private method.
+
+package p
+
+type Exported interface {
+ private()
+}
+
+type Implementation struct{}
+
+func (p *Implementation) private() {}
+
+var X = new(Implementation)
+
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/prog.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/prog.go
new file mode 100644
index 000000000..abea7d625
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/private.dir/prog.go
@@ -0,0 +1,33 @@
+// 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.
+
+// Test that unexported methods are not visible outside the package.
+// Does not compile.
+
+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-4.9/gcc/testsuite/go.test/test/interface/private.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/private.go
new file mode 100644
index 000000000..a0da249c9
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/private.go
@@ -0,0 +1,10 @@
+// errorcheckdir
+
+// 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.
+
+// Test that unexported methods are not visible outside the package.
+// Does not compile.
+
+package ignored
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/receiver.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/receiver.go
new file mode 100644
index 000000000..4511ab3b4
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/receiver.go
@@ -0,0 +1,121 @@
+// run
+
+// 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.
+
+// Test Implicit methods for embedded types and
+// 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/gcc-4.9/gcc/testsuite/go.test/test/interface/receiver1.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/receiver1.go
new file mode 100644
index 000000000..2b7ccdc1a
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/receiver1.go
@@ -0,0 +1,59 @@
+// errorcheck
+
+// 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.
+
+// Verify compiler complains about missing implicit methods.
+// Does not compile.
+
+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/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive.go
new file mode 100644
index 000000000..fcc88331e
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive.go
@@ -0,0 +1,21 @@
+// 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 recursive
+
+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/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive1.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive1.go
new file mode 100644
index 000000000..441f0ecaa
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive1.go
@@ -0,0 +1,15 @@
+// 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.
+
+// Mutually recursive type definitions imported and used by recursive1.go.
+
+package p
+
+type I1 interface {
+ F() I2
+}
+
+type I2 interface {
+ I1
+}
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive2.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive2.go
new file mode 100644
index 000000000..e8048c672
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.dir/recursive2.go
@@ -0,0 +1,20 @@
+// 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.
+
+// Test 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-4.9/gcc/testsuite/go.test/test/interface/recursive1.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.go
new file mode 100644
index 000000000..62f610884
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/recursive1.go
@@ -0,0 +1,9 @@
+// compiledir
+
+// 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.
+
+// Mutually recursive type definitions imported and used by recursive1.go.
+
+package ignored
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/returntype.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/returntype.go
new file mode 100644
index 000000000..4d86f3918
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/returntype.go
@@ -0,0 +1,38 @@
+// run
+
+// 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.
+
+// Test interface methods with different return types are distinct.
+
+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() {
+ 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()
+}
diff --git a/gcc-4.9/gcc/testsuite/go.test/test/interface/struct.go b/gcc-4.9/gcc/testsuite/go.test/test/interface/struct.go
new file mode 100644
index 000000000..f60819ca8
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/go.test/test/interface/struct.go
@@ -0,0 +1,156 @@
+// run
+
+// 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.
+
+// Test 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)
+ }
+}