Source file test/fixedbugs/issue83209.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 trace []string
    10  
    11  func src(s []int) []int { trace = append(trace, "src"); return s }
    12  
    13  func size(n int) int { trace = append(trace, "size"); return n }
    14  
    15  func main() {
    16  	// The length is a call, inlined.
    17  	_ = append(src([]int{9}), make([]int, size(2))...)
    18  	check("call")
    19  
    20  	// The length is a closure called in place, inlined by another path.
    21  	_ = append(src([]int{9}), make([]int, func() int {
    22  		trace = append(trace, "size")
    23  		return 2
    24  	}())...)
    25  	check("closure")
    26  }
    27  
    28  func check(what string) {
    29  	if len(trace) != 2 || trace[0] != "src" || trace[1] != "size" {
    30  		println("after the", what, "append, trace has", len(trace), "entries, want 2:")
    31  		for _, s := range trace {
    32  			println("\t", s)
    33  		}
    34  		panic("append(x, make([]T, y)...) lost a side effect")
    35  	}
    36  	trace = nil
    37  }
    38  

View as plain text