Source file
test/fixedbugs/issue83150.go
1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import "strings"
14
15 var s = make([]int, 8)
16
17 func at(i, c int) int { return s[i-c] }
18
19
20 func neg() int { return at(-1, 2) }
21
22
23 func big() int { return s[40] }
24
25
26 func slice() []int { return s[:40] }
27
28 func check(f func(), want string) {
29 defer func() {
30 r := recover()
31 if r == nil {
32 panic("no panic (bug)")
33 }
34 got := r.(error).Error()
35 if !strings.Contains(got, want) {
36 panic("got " + got + ", want " + want)
37 }
38 }()
39 f()
40 }
41
42 func main() {
43 check(func() { neg() }, "index out of range [-3]")
44 check(func() { big() }, "index out of range [40] with length 8")
45 check(func() { slice() }, "slice bounds out of range [:40] with capacity 8")
46 }
47
View as plain text