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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [cmp6.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// errchk $G -e $D/$F.go
2
 
3
// Copyright 2010 The Go Authors. All rights reserved.
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file.
6
 
7
package main
8
 
9
func use(bool) {}
10
 
11
type T1 *int
12
type T2 *int
13
 
14
type T3 struct{ z []int }
15
 
16
var t3 T3
17
 
18
func main() {
19
        // Arguments to comparison must be
20
        // assignable one to the other (or vice versa)
21
        // so chan int can be compared against
22
        // directional channels but channel of different
23
        // direction cannot be compared against each other.
24
        var c1 chan<- int
25
        var c2 <-chan int
26
        var c3 chan int
27
 
28
        use(c1 == c2) // ERROR "invalid operation|incompatible"
29
        use(c2 == c1) // ERROR "invalid operation|incompatible"
30
        use(c1 == c3)
31
        use(c2 == c2)
32
        use(c3 == c1)
33
        use(c3 == c2)
34
 
35
        // Same applies to named types.
36
        var p1 T1
37
        var p2 T2
38
        var p3 *int
39
 
40
        use(p1 == p2) // ERROR "invalid operation|incompatible"
41
        use(p2 == p1) // ERROR "invalid operation|incompatible"
42
        use(p1 == p3)
43
        use(p2 == p2)
44
        use(p3 == p1)
45
        use(p3 == p2)
46
 
47
        // Comparison of structs should have a good message
48
        use(t3 == t3) // ERROR "struct|expected"
49
 
50
        // Slices, functions, and maps too.
51
        var x []int
52
        var f func()
53
        var m map[int]int
54
        use(x == x) // ERROR "slice can only be compared to nil"
55
        use(f == f) // ERROR "func can only be compared to nil"
56
        use(m == m) // ERROR "map can only be compared to nil"
57
 
58
        // Comparison with interface that cannot return true
59
        // (would panic).
60
        var i interface{}
61
        use(i == x) // ERROR "invalid operation"
62
        use(x == i) // ERROR "invalid operation"
63
        use(i == f) // ERROR "invalid operation"
64
        use(f == i) // ERROR "invalid operation"
65
        use(i == m) // ERROR "invalid operation"
66
        use(m == i) // ERROR "invalid operation"
67
}

powered by: WebSVN 2.1.0

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