Source file test/typeparam/issue376214.go

     1  // run
     2  
     3  // Copyright 2022 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  func add[S ~string | ~[]byte](buf *[]byte, s S) {
    10  	*buf = append(*buf, s...)
    11  }
    12  
    13  func main() {
    14  	var buf []byte
    15  	add(&buf, "foo")
    16  	add(&buf, []byte("bar"))
    17  	if string(buf) != "foobar" {
    18  		panic("got " + string(buf))
    19  	}
    20  }
    21  

View as plain text