OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [fixedbugs/] [bug248.dir/] [bug2.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
package main
2
 
3
import (
4
        p0 "./bug0"
5
        p1 "./bug1"
6
 
7
        "reflect"
8
        "strings"
9
)
10
 
11
var v0 p0.T
12
var v1 p1.T
13
 
14
type I0 interface {
15
        M(p0.T)
16
}
17
 
18
type I1 interface {
19
        M(p1.T)
20
}
21
 
22
type t0 int
23
 
24
func (t0) M(p0.T) {}
25
 
26
type t1 float64
27
 
28
func (t1) M(p1.T) {}
29
 
30
var i0 I0 = t0(0) // ok
31
var i1 I1 = t1(0) // ok
32
 
33
var p0i p0.I = t0(0) // ok
34
var p1i p1.I = t1(0) // ok
35
 
36
func main() {
37
        // check that reflect paths are correct,
38
        // meaning that reflect data for v0, v1 didn't get confused.
39
 
40
        // path is full (rooted) path name.  check suffix for gc, prefix for gccgo
41
        if s := reflect.TypeOf(v0).PkgPath(); !strings.HasSuffix(s, "/bug0") && !strings.HasPrefix(s, "bug0") {
42
                println("bad v0 path", len(s), s)
43
                panic("fail")
44
        }
45
        if s := reflect.TypeOf(v1).PkgPath(); !strings.HasSuffix(s, "/bug1") && !strings.HasPrefix(s, "bug1") {
46
                println("bad v1 path", s)
47
                panic("fail")
48
        }
49
 
50
        // check that dynamic interface check doesn't get confused
51
        var i interface{} = t0(0)
52
        if _, ok := i.(I1); ok {
53
                println("used t0 as i1")
54
                panic("fail")
55
        }
56
        if _, ok := i.(p1.I); ok {
57
                println("used t0 as p1.I")
58
                panic("fail")
59
        }
60
 
61
        i = t1(1)
62
        if _, ok := i.(I0); ok {
63
                println("used t1 as i0")
64
                panic("fail")
65
        }
66
        if _, ok := i.(p0.I); ok {
67
                println("used t1 as p0.I")
68
                panic("fail")
69
        }
70
 
71
        // check that type switch works.
72
        // the worry is that if p0.T and p1.T have the same hash,
73
        // the binary search will handle one of them incorrectly.
74
        for j := 0; j < 3; j++ {
75
                switch j {
76
                case 0:
77
                        i = p0.T{}
78
                case 1:
79
                        i = p1.T{}
80
                case 2:
81
                        i = 3.14
82
                }
83
                switch i.(type) {
84
                case p0.T:
85
                        if j != 0 {
86
                                println("type switch p0.T")
87
                                panic("fail")
88
                        }
89
                case p1.T:
90
                        if j != 1 {
91
                                println("type switch p1.T")
92
                                panic("fail")
93
                        }
94
                default:
95
                        if j != 2 {
96
                                println("type switch default", j)
97
                                panic("fail")
98
                        }
99
                }
100
        }
101
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.