Source file test/makemap.go
1 // errorcheck 2 3 // Copyright 2017 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 // Ensure that typed non-integer, negative and too large 8 // values are not accepted as size argument in make for 9 // maps. 10 11 package main 12 13 type T map[int]int 14 15 var sink T 16 17 func main() { 18 sink = make(T, -1) // ERROR "negative size argument in make.*|must not be negative" 19 sink = make(T, uint64(1<<63)) // ERROR "size argument too large in make.*|overflows int" 20 21 // Test that errors are emitted at call sites, not const declarations 22 const x = -1 23 sink = make(T, x) // ERROR "negative size argument in make.*|must not be negative" 24 const y = uint64(1 << 63) 25 sink = make(T, y) // ERROR "size argument too large in make.*|overflows int" 26 27 sink = make(T, 0.5) // ERROR "constant 0.5 truncated to integer|truncated to int" 28 sink = make(T, 1.0) 29 sink = make(T, float32(1.0)) // ERROR "non-integer size argument in make.*|must be integer" 30 sink = make(T, float64(1.0)) // ERROR "non-integer size argument in make.*|must be integer" 31 sink = make(T, 1+0i) 32 sink = make(T, complex64(1+0i)) // ERROR "non-integer size argument in make.*|must be integer" 33 sink = make(T, complex128(1+0i)) // ERROR "non-integer size argument in make.*|must be integer" 34 } 35