blob: 498c2ec45bd88c717d68d37b23dbfc97d3aafb4d [file] [log] [blame]
Russ Cox57eb06f2012-02-16 23:51:04 -05001// errorcheck
Russ Cox7ca40632011-09-19 13:11:24 -04002
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07003// Copyright 2011 The Go Authors. All rights reserved.
Russ Cox7ca40632011-09-19 13:11:24 -04004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
Rob Pike501f0b52012-02-23 18:47:26 +11007// Test map declarations of many types, including erroneous ones.
8// Does not compile.
9
Russ Cox7ca40632011-09-19 13:11:24 -040010package main
11
Russ Cox7ca40632011-09-19 13:11:24 -040012type v bool
13
14var (
15 // valid
Russ Cox5bb54b82011-11-13 22:58:08 -050016 _ 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
Russ Cox7ca40632011-09-19 13:11:24 -040026 _ 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
Russ Cox7ca40632011-09-19 13:11:24 -040034 _ map[*int]v
Russ Cox196b6632011-12-12 22:22:09 -050035 _ map[struct{}]v
36 _ map[[10]int]v
Russ Cox7ca40632011-09-19 13:11:24 -040037
38 // invalid
Russ Cox5bb54b82011-11-13 22:58:08 -050039 _ map[[]int]v // ERROR "invalid map key"
Russ Cox5bb54b82011-11-13 22:58:08 -050040 _ map[func()]v // ERROR "invalid map key"
41 _ map[map[int]int]v // ERROR "invalid map key"
Russ Cox6363fc52012-06-07 03:06:40 -040042 _ 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
Russ Cox7ca40632011-09-19 13:11:24 -040050)
Russ Cox6363fc52012-06-07 03:06:40 -040051
52type T1 []int
53type T2 struct { F T1 }
54type T3 []T4
55type T4 struct { F T3 }
56
57type T5 *int
58type T6 struct { F T5 }
59type T7 *T4
60type T8 struct { F *T7 }
Alberto Donizetti1737aef2017-04-22 15:28:58 +020061
62func 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}