Home | History | Annotate | Download | only in test
      1 // errorcheck
      2 
      3 // Copyright 2011 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 map declarations of many types, including erroneous ones.
      8 // Does not compile.
      9 
     10 package main
     11 
     12 type v bool
     13 
     14 var (
     15 	// valid
     16 	_ map[int8]v
     17 	_ map[uint8]v
     18 	_ map[int16]v
     19 	_ map[uint16]v
     20 	_ map[int32]v
     21 	_ map[uint32]v
     22 	_ map[int64]v
     23 	_ map[uint64]v
     24 	_ map[int]v
     25 	_ map[uint]v
     26 	_ map[uintptr]v
     27 	_ map[float32]v
     28 	_ map[float64]v
     29 	_ map[complex64]v
     30 	_ map[complex128]v
     31 	_ map[bool]v
     32 	_ map[string]v
     33 	_ map[chan int]v
     34 	_ map[*int]v
     35 	_ map[struct{}]v
     36 	_ map[[10]int]v
     37 
     38 	// invalid
     39 	_ map[[]int]v       // ERROR "invalid map key"
     40 	_ map[func()]v      // ERROR "invalid map key"
     41 	_ map[map[int]int]v // ERROR "invalid map key"
     42 	_ map[T1]v    // ERROR "invalid map key"
     43 	_ map[T2]v    // ERROR "invalid map key"
     44 	_ map[T3]v    // ERROR "invalid map key"
     45 	_ map[T4]v    // ERROR "invalid map key"
     46 	_ map[T5]v
     47 	_ map[T6]v
     48 	_ map[T7]v
     49 	_ map[T8]v
     50 )
     51 
     52 type T1 []int
     53 type T2 struct { F T1 }
     54 type T3 []T4
     55 type T4 struct { F T3 }
     56 
     57 type T5 *int
     58 type T6 struct { F T5 }
     59 type T7 *T4
     60 type T8 struct { F *T7 }
     61 
     62 func main() {
     63 	m := make(map[int]int)
     64 	delete()        // ERROR "missing arguments"
     65 	delete(m)       // ERROR "missing second \(key\) argument"
     66 	delete(m, 2, 3) // ERROR "too many arguments"
     67 	delete(1, m)    // ERROR "first argument to delete must be map"
     68 }