diff options
author | Robert Griesemer <gri@golang.org> | 2022-01-06 18:02:30 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2022-01-07 22:40:23 +0000 |
commit | c74be77e63c0281abb45dbf9de31fa05a6824934 (patch) | |
tree | 7d9c195b07ab12ad80fc5f408969b406cf155db9 /test | |
parent | be26ca972d2149df09e70789fdf284da01c5e9d8 (diff) | |
download | go-c74be77e63c0281abb45dbf9de31fa05a6824934.tar.gz go-c74be77e63c0281abb45dbf9de31fa05a6824934.zip |
cmd/compile: accept string|[]byte-constrained 2nd argument in append
Similarly to what we do for the built-in function `copy`,
where we allow a string as 2nd argument to append, also
permit a type parameter constrained by string|[]byte.
While at it, change date in the manual.go2 test files so
that we don't need to constantly correct it when copying
a test case from that file into a proper test file.
Fixes #50281.
Change-Id: I23fed66736aa07bb3c481fe97313e828425ac448
Reviewed-on: https://go-review.googlesource.com/c/go/+/376214
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/typeparam/issue376214.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/typeparam/issue376214.go b/test/typeparam/issue376214.go new file mode 100644 index 00000000000..8f94f4107d4 --- /dev/null +++ b/test/typeparam/issue376214.go @@ -0,0 +1,20 @@ +// run -gcflags=-G=3 + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func add[S ~string | ~[]byte](buf *[]byte, s S) { + *buf = append(*buf, s...) +} + +func main() { + var buf []byte + add(&buf, "foo") + add(&buf, []byte("bar")) + if string(buf) != "foobar" { + panic("got " + string(buf)) + } +} |