| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2024 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 |
package main |
| 8 |
|
| 9 |
func main() { |
| 10 |
mustPanic(func() { |
| 11 |
f1(1) |
| 12 |
}) |
| 13 |
f2(1, 0) // must not panic |
| 14 |
mustPanic(func() { |
| 15 |
f2(1, 2) |
| 16 |
}) |
| 17 |
} |
| 18 |
|
| 19 |
var v []func() |
| 20 |
|
| 21 |
//go:noinline |
| 22 |
func f1(i int) { |
| 23 |
v = make([]func(), -2|i) |
| 24 |
} |
| 25 |
|
| 26 |
//go:noinline |
| 27 |
func f2(i, j int) { |
| 28 |
if j > 0 { |
| 29 |
v = make([]func(), -2|i) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
func mustPanic(f func()) { |
| 34 |
defer func() { |
| 35 |
r := recover() |
| 36 |
if r == nil { |
| 37 |
panic("didn't panic") |
| 38 |
} |
| 39 |
}() |
| 40 |
f() |
| 41 |
} |