modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/makemap.go (about)

     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.*"
    19  	sink = make(T, uint64(1<<63)) // ERROR "size argument too large in make.*"
    20  
    21  	sink = make(T, 0.5) // ERROR "constant 0.5 truncated to integer"
    22  	sink = make(T, 1.0)
    23  	sink = make(T, float32(1.0)) // ERROR "non-integer size argument in make.*"
    24  	sink = make(T, float64(1.0)) // ERROR "non-integer size argument in make.*"
    25  	sink = make(T, 1.0)
    26  	sink = make(T, float32(1.0)) // ERROR "non-integer size argument in make.*"
    27  	sink = make(T, float64(1.0)) // ERROR "non-integer size argument in make.*"
    28  	sink = make(T, 1+0i)
    29  	sink = make(T, complex64(1+0i))  // ERROR "non-integer size argument in make.*"
    30  	sink = make(T, complex128(1+0i)) // ERROR "non-integer size argument in make.*"
    31  	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  }