Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / gcc / testsuite / go.test / test / named1.go
blob600e502f9e8f31c8926a5665579483cd3f3c85a6
1 // errchk $G -e $D/$F.go
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.
7 // Test that basic operations on named types are valid
8 // and preserve the type.
10 package main
12 type Bool bool
14 type Map map[int]int
16 func (Map) M() {}
18 type Slice []byte
20 var slice Slice
22 func asBool(Bool) {}
23 func asString(String) {}
25 type String string
27 func main() {
28 var (
29 b Bool = true
30 i, j int
31 c = make(chan int)
32 m = make(Map)
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"
43 _, b = m[2] // ERROR "cannot .* bool.*type Bool"
44 m[2] = 1, b // ERROR "cannot use.*type Bool.*as type bool"
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"
50 _, b = <-c // ERROR "cannot .* bool.*type Bool"
51 _ = b
53 var inter interface{}
54 _, b = inter.(Map) // ERROR "cannot .* bool.*type Bool"
55 _ = b
57 var minter interface {
58 M()
60 _, b = minter.(Map) // ERROR "cannot .* bool.*type Bool"
61 _ = b
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
67 asString(String(slice)) // ERROR "cannot .*type Slice.*type String"