modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue6055.go (about)

     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  
     9  import "runtime"
    10  
    11  type Closer interface {
    12  	Close()
    13  }
    14  
    15  func nilInterfaceDeferCall() {
    16  	defer func() {
    17  		// make sure a traceback happens with jmpdefer on the stack
    18  		runtime.GC()
    19  	}()
    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  }