Home | History | Annotate | Download | only in test
      1 // errorcheck
      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 // Does not compile.
     10 
     11 package main
     12 
     13 type Bool bool
     14 
     15 type Map map[int]int
     16 
     17 func (Map) M() {}
     18 
     19 type Slice []byte
     20 
     21 var slice Slice
     22 
     23 func asBool(Bool)     {}
     24 func asString(String) {}
     25 
     26 type String string
     27 
     28 func main() {
     29 	var (
     30 		b    Bool = true
     31 		i, j int
     32 		c    = make(chan int)
     33 		m    = make(Map)
     34 	)
     35 
     36 	asBool(b)
     37 	asBool(!b)
     38 	asBool(true)
     39 	asBool(*&b)
     40 	asBool(Bool(true))
     41 	asBool(1 != 2) // ok now
     42 	asBool(i < j)  // ok now
     43 
     44 	_, b = m[2] // ok now
     45 
     46 	var inter interface{}
     47 	_, b = inter.(Map) // ok now
     48 	_ = b
     49 
     50 	var minter interface {
     51 		M()
     52 	}
     53 	_, b = minter.(Map) // ok now
     54 	_ = b
     55 
     56 	_, bb := <-c
     57 	asBool(bb) // ERROR "cannot use.*type bool.*as type Bool"
     58 	_, b = <-c // ok now
     59 	_ = b
     60 
     61 	asString(String(slice)) // ok
     62 }
     63