]> Cypherpunks.ru repositories - gostls13.git/blob - test/named1.go
replace non-blocking send, receive syntax with select
[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         ////TODO(rsc): uncomment when this syntax is valid for receive+check closed
47         ////    _, b = <-c // ERROR "cannot .* bool.*type Bool"
48         ////    _ = b
49
50         var inter interface{}
51         _, b = inter.(Map) // ERROR "cannot .* bool.*type Bool"
52         _ = b
53
54         var minter interface {
55                 M()
56         }
57         _, b = minter.(Map) // ERROR "cannot .* bool.*type Bool"
58         _ = b
59
60         asBool(closed(c)) // ERROR "cannot use.*type bool.*as type Bool"
61         b = closed(c)     // ERROR "cannot use.*type bool.*type Bool"
62         _ = b
63
64         asString(String(slice)) // ERROR "cannot .*type Slice.*type String"
65 }