Keith Randall | a97a91d | 2013-08-07 14:03:50 -0700 | [diff] [blame] | 1 | // run |
| 2 | |
| 3 | // Copyright 2013 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 | |
Keith Randall | 36f223d | 2013-08-09 15:27:45 -0700 | [diff] [blame] | 9 | import "runtime" |
| 10 | |
Keith Randall | a97a91d | 2013-08-07 14:03:50 -0700 | [diff] [blame] | 11 | type Closer interface { |
| 12 | Close() |
| 13 | } |
| 14 | |
| 15 | func nilInterfaceDeferCall() { |
Keith Randall | 36f223d | 2013-08-09 15:27:45 -0700 | [diff] [blame] | 16 | defer func() { |
| 17 | // make sure a traceback happens with jmpdefer on the stack |
| 18 | runtime.GC() |
| 19 | }() |
Keith Randall | a97a91d | 2013-08-07 14:03:50 -0700 | [diff] [blame] | 20 | var x Closer |
| 21 | defer x.Close() |
| 22 | } |
| 23 | |
| 24 | func shouldPanic(f func()) { |
| 25 | defer func() { |
| 26 | if recover() == nil { |
| 27 | panic("did not panic") |
| 28 | } |
| 29 | }() |
| 30 | f() |
| 31 | } |
| 32 | |
| 33 | func main() { |
| 34 | shouldPanic(nilInterfaceDeferCall) |
| 35 | } |