Source file test/fixedbugs/issue82722.go

     1  // run
     2  
     3  // Copyright 2026 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  //go:noinline
    10  func run(f func()) { f() }
    11  
    12  func F1() func() {
    13  	x := 1
    14  	return func() {
    15  		check := func() {
    16  			run(func() {
    17  				go func() {
    18  					if x != 1 {
    19  						panic("unexpected x value")
    20  					}
    21  				}()
    22  			})
    23  		}
    24  		check()
    25  	}
    26  }
    27  
    28  func F2() func() {
    29  	x := 42
    30  	return func() {
    31  		x := x
    32  		y := x
    33  		z := 42
    34  		check := func() {
    35  			run(func() {
    36  				go func() {
    37  					if x != 42 {
    38  						panic("unexpected x value")
    39  					}
    40  					if y != 42 || y != x {
    41  						panic("unexpected y value")
    42  					}
    43  					if z != 42 {
    44  						panic("unexpected z value")
    45  					}
    46  				}()
    47  			})
    48  		}
    49  		check()
    50  	}
    51  }
    52  
    53  //go:noinline
    54  func use(a int64) {}
    55  
    56  func G() {
    57  	x := int64(1000)
    58  	run(func() {
    59  		g := func() {
    60  			run(func() {
    61  				func() {
    62  					use(x)
    63  					if x != 1000 {
    64  						panic("unexpected x value")
    65  					}
    66  				}()
    67  			})
    68  		}
    69  		g()
    70  	})
    71  }
    72  
    73  func main() {
    74  	F1()()
    75  	F2()()
    76  	G()
    77  }
    78  

View as plain text