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

     1  // errorcheck
     2  
     3  // Copyright 2014 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  // issue 7150: array index out of bounds error off by one
     8  
     9  package main
    10  
    11  func main() {
    12  	_ = [0]int{-1: 50}              // ERROR "index must be non-negative integer constant"
    13  	_ = [0]int{0: 0}                // ERROR "index 0 out of bounds \[0:0\]"
    14  	_ = [0]int{5: 25}               // ERROR "index 5 out of bounds \[0:0\]"
    15  	_ = [10]int{2: 10, 15: 30}      // ERROR "index 15 out of bounds \[0:10\]"
    16  	_ = [10]int{5: 5, 1: 1, 12: 12} // ERROR "index 12 out of bounds \[0:10\]"
    17  }