New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/types, types2: append within a generic function does not compile #50281
Comments
I modified the above program, see https://gotipplay.golang.org/p/j31fyLkpZcL, it works now.
Because I am not familiar with type parameters, I do not know if this modification changes its function. Thank you. |
Please ingore the above reply, the above mofication changes its function. 🙂 |
Isn't this already disallowed by the current spec because byteseq doesn't have a specific type? |
The simple case is package p
func _[S string|[]byte](s S) {
var buf []byte
_ = append(buf, s...)
} which is currently disallowed because |
Change https://golang.org/cl/376214 mentions this issue: |
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 golang#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>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
latest beta release
What did you do?
A generic function with a union constraint of
[]byte | string
cannot append to a[]byte
.https://gotipplay.golang.org/p/WGG7g3HTfZ-
I expect this is a duplicate of a known issue but so far I was not able to find anytinhg. Similar functions are explicitly mentioned in the proposal: https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#composite-types-in-constraints
What did you expect to see?
The program compiles.
What did you see instead?
The text was updated successfully, but these errors were encountered: