Source file test/fixedbugs/issue83036.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  import "fmt"
    10  
    11  var (
    12  	seen  []bool
    13  	calls int
    14  	sink  func()
    15  )
    16  
    17  //go:noinline
    18  func wait(refusing bool) bool {
    19  	seen = append(seen, refusing)
    20  	return true
    21  }
    22  
    23  //go:noinline
    24  func probe() bool {
    25  	calls++
    26  	return calls >= 3
    27  }
    28  
    29  func note() {
    30  	if sink != nil {
    31  		sink()
    32  	}
    33  }
    34  
    35  func loop(first bool) {
    36  	refusing := false
    37  	for w := !first; ; w = true {
    38  		if w && !wait(refusing) {
    39  			note()
    40  			return
    41  		}
    42  		if probe() {
    43  			return
    44  		}
    45  		refusing = true
    46  	}
    47  }
    48  
    49  func main() {
    50  	for _, first := range []bool{false, true} {
    51  		seen = nil
    52  		calls = 0
    53  		loop(first)
    54  		want := "[false true true]"
    55  		if first {
    56  			want = "[true true]"
    57  		}
    58  		if got := fmt.Sprint(seen); got != want {
    59  			panic(fmt.Sprintf("first=%v: got %s, want %s", first, got, want))
    60  		}
    61  	}
    62  }
    63  

View as plain text