| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2016 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 |
var fail bool |
| 10 |
|
| 11 |
type Closer interface { |
| 12 |
Close() |
| 13 |
} |
| 14 |
|
| 15 |
func nilInterfaceDeferCall() { |
| 16 |
var x Closer |
| 17 |
defer x.Close() |
| 18 |
// if it panics when evaluating x.Close, it should not reach here |
| 19 |
fail = true |
| 20 |
} |
| 21 |
|
| 22 |
func shouldPanic(f func()) { |
| 23 |
defer func() { |
| 24 |
if recover() == nil { |
| 25 |
panic("did not panic") |
| 26 |
} |
| 27 |
}() |
| 28 |
f() |
| 29 |
} |
| 30 |
|
| 31 |
func main() { |
| 32 |
shouldPanic(nilInterfaceDeferCall) |
| 33 |
if fail { |
| 34 |
panic("fail") |
| 35 |
} |
| 36 |
} |