Source file test/fixedbugs/issue78303_1.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  var n = 1
    10  
    11  //go:noinline
    12  func bug(a func(int)) {
    13  	m := int64(len("x"[:n])) - (1 << 62)
    14  	for i, j := int64(-1<<63), 0; i < m; i, j = i+(1<<62), j+1 {
    15  		if j == 2 {
    16  			a(3)
    17  			return
    18  		}
    19  	}
    20  	a(2)
    21  }
    22  
    23  func main() {
    24  	var r int
    25  	var set bool
    26  	bug(func(x int) {
    27  		if set {
    28  			panic("called twice")
    29  		}
    30  		set = true
    31  		r = x
    32  	})
    33  	if !set {
    34  		panic("not called")
    35  	}
    36  	if r != 2 {
    37  		panic("got wrong result")
    38  	}
    39  }
    40  

View as plain text