| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2025 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 callRecover() { |
| 10 |
if recover() != nil { |
| 11 |
println("recovered") |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
type T int |
| 16 |
|
| 17 |
func (*T) M() { callRecover() } |
| 18 |
|
| 19 |
type S struct{ *T } // has a wrapper (*S).M wrapping (*T.M) |
| 20 |
|
| 21 |
var p = &S{new(T)} |
| 22 |
|
| 23 |
var fn = (*S).M // using a function pointer to force using the wrapper |
| 24 |
|
| 25 |
func main() { |
| 26 |
mustPanic(func() { |
| 27 |
defer fn(p) |
| 28 |
panic("XXX") |
| 29 |
}) |
| 30 |
} |
| 31 |
|
| 32 |
func mustPanic(f func()) { |
| 33 |
defer func() { |
| 34 |
r := recover() |
| 35 |
if r == nil { |
| 36 |
panic("didn't panic") |
| 37 |
} |
| 38 |
}() |
| 39 |
f() |
| 40 |
} |