| 1 |
// run |
| 2 |
|
| 3 |
package main |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
"reflect" |
| 8 |
"strings" |
| 9 |
) |
| 10 |
|
| 11 |
// Copyright 2019 The Go Authors. All rights reserved. |
| 12 |
// Use of this source code is governed by a BSD-style |
| 13 |
// license that can be found in the LICENSE file. |
| 14 |
|
| 15 |
func main() { |
| 16 |
defer func() { |
| 17 |
e := recover() |
| 18 |
if e == nil { |
| 19 |
panic("should have panicked") |
| 20 |
} |
| 21 |
text := fmt.Sprintf("%s", e) // handles both string and runtime.errorString |
| 22 |
if !strings.HasPrefix(text, "reflect:") { |
| 23 |
panic("wanted a reflect error, got this instead:\n" + text) |
| 24 |
} |
| 25 |
}() |
| 26 |
r := reflect.MakeFunc(reflect.TypeOf(func() error { return nil }), |
| 27 |
func(args []reflect.Value) []reflect.Value { |
| 28 |
var x [1]reflect.Value |
| 29 |
return x[:] |
| 30 |
}).Interface().(func() error) |
| 31 |
r() |
| 32 |
} |