]> Cypherpunks.ru repositories - gostls13.git/blob - test/named1.go
test: Match gccgo error messages.
[gostls13.git] / test / named1.go
1 // errchk $G -e $D/$F.go
2
3 // Copyright 2009 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 // Test that basic operations on named types are valid
8 // and preserve the type.
9
10 package main
11
12 type Bool bool
13
14 type Map map[int]int
15
16 func (Map) M() {}
17
18 type Slice []byte
19
20 var slice Slice
21
22 func asBool(Bool)     {}
23 func asString(String) {}
24
25 type String string
26
27 func main() {
28         var (
29                 b    Bool = true
30                 i, j int
31                 c    = make(chan int)
32                 m    = make(Map)
33         )
34
35         asBool(b)
36         asBool(!b)
37         asBool(true)
38         asBool(*&b)
39         asBool(Bool(true))
40         asBool(1 != 2) // ERROR "cannot use.*type bool.*as type Bool"
41         asBool(i < j)  // ERROR "cannot use.*type bool.*as type Bool"
42
43         _, b = m[2] // ERROR "cannot .* bool.*type Bool"
44         m[2] = 1, b // ERROR "cannot use.*type Bool.*as type bool"
45
46         b = c <- 1 // ERROR "cannot use.*type bool.*type Bool"
47         _ = b
48         asBool(c <- 1) // ERROR "cannot use.*type bool.*as type Bool"
49
50         _, b = <-c // ERROR "cannot .* bool.*type Bool"
51         _ = b
52
53         var inter interface{}
54         _, b = inter.(Map) // ERROR "cannot .* bool.*type Bool"
55         _ = b
56
57         var minter interface {
58                 M()
59         }
60         _, b = minter.(Map) // ERROR "cannot .* bool.*type Bool"
61         _ = b
62
63         asBool(closed(c)) // ERROR "cannot use.*type bool.*as type Bool"
64         b = closed(c)     // ERROR "cannot use.*type bool.*type Bool"
65         _ = b
66
67         asString(String(slice)) // ERROR "cannot .*type Slice.*type String"
68 }