blob: 63998d708c31228ce5adc2d028de23d0800025e6 [file] [log] [blame]
Dan Willemsena3223282018-02-27 19:41:43 -08001// 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
11package main
12
13type T map[int]int
14
15var sink T
16
17func main() {
18 sink = make(T, -1) // ERROR "negative size argument in make.*"
19 sink = make(T, uint64(1<<63)) // ERROR "size argument too large in make.*"
20
Dan Willemsenc7413322018-08-27 23:21:26 -070021 // 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.*"
24 const y = uint64(1 << 63)
25 sink = make(T, y) // ERROR "size argument too large in make.*"
26
Dan Willemsena3223282018-02-27 19:41:43 -080027 sink = make(T, 0.5) // ERROR "constant 0.5 truncated to integer"
28 sink = make(T, 1.0)
29 sink = make(T, float32(1.0)) // ERROR "non-integer size argument in make.*"
30 sink = make(T, float64(1.0)) // ERROR "non-integer size argument in make.*"
Dan Willemsena3223282018-02-27 19:41:43 -080031 sink = make(T, 1+0i)
32 sink = make(T, complex64(1+0i)) // ERROR "non-integer size argument in make.*"
33 sink = make(T, complex128(1+0i)) // ERROR "non-integer size argument in make.*"
34}