Source file test/fixedbugs/issue79909.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 "strconv"
    10  
    11  var sink []int64
    12  
    13  //go:noinline
    14  func f() int64 {
    15  	var s []int64
    16  	for i := int64(1); i <= 4; i++ {
    17  		s = append(s, i)
    18  	}
    19  	if cap(s) != 4 {
    20  		return -1
    21  	}
    22  	sum := int64(0)
    23  	for idx, v := range s {
    24  		sum = sum*10 + v
    25  		if idx == 0 {
    26  			s = s[3:3]
    27  			s = append(s, 9, 9)
    28  		}
    29  	}
    30  	sink = s
    31  	return sum
    32  }
    33  
    34  func main() {
    35  	if got := f(); got != 1234 {
    36  		panic("unexpected result: " + strconv.Itoa(int(got)))
    37  	}
    38  }
    39  

View as plain text