Source file test/fixedbugs/issue43942.go

     1  // run
     2  
     3  // Copyright 2022 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 "log"
    10  
    11  func main() {
    12  	defer func() {
    13  		expect(5, recover())
    14  	}()
    15  	func() {
    16  		expect(nil, recover())
    17  		defer func() {
    18  			defer func() {
    19  				defer func() {
    20  					defer func() {
    21  						expect(3, recover())
    22  					}()
    23  					defer panic(3)
    24  					panic(2)
    25  				}()
    26  				defer func() {
    27  					expect(1, recover())
    28  				}()
    29  				panic(1)
    30  			}()
    31  		}()
    32  	}()
    33  	func() {
    34  		for {
    35  			defer func() {
    36  				defer panic(5)
    37  			}()
    38  			break
    39  		}
    40  		panic(4)
    41  	}()
    42  }
    43  
    44  func expect(want, have interface{}) {
    45  	if want != have {
    46  		log.Fatalf("want %v, have %v", want, have)
    47  	}
    48  }
    49  

View as plain text