-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
spec: can't range over parameter constrained by union type #51053
Comments
Thanks. This is expected. We may try to tackle this for 1.19 or 1.20. The key issue is that we will need to develop some theory and mechanism for generic types that are not covered by the type parameter list. In this case the value type of If you look closely at the code in https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#composite-types-in-constraints you will see that it only uses |
CC @griesemer |
Also, one case that can be investigated is range over func f[SliceOrMapType map[int]int | []int](sliceOrMap SliceOrMapType) {
for range sliceOrMap {}
} Currently, reports an error:
|
@mymmrac Yes, that is expected in Go 1.18. |
Yep, I know, just wanted to mention it, because it seems to be related to this issue and it would be good to have similar fix in future releases) |
Rolling forward to 1.20. Please comment if you disagree. Thanks. |
No progress on this issue. Rolling forward to 1.22. |
Rolling forward to 1.23. |
What did you do?
Tried to execute this program: https://go.dev/play/p/JdOGVlCgCHh?v=gotip
It's fairly short, but to have the critical code here too:
What did you expect to see?
Expected it to compile and print the runes, as using any of the two types alone in the interface does actually work.
What did you see instead?
Additional notes
type byteseq interface { string | []byte }
is used. But then I realized there's an ambiguity, as one might want to iterate a string as []byte or as []rune. It's not obvious what should even happen, and at least we should try to clarify it somewhere (maybe I missed something in the documentation).range []rune(runes)
works, but it's unclear the translation will be transparent.interface { string | chan string }
would also be iterable but won't work. This might be another issue, I'm only mentioning it for context.The text was updated successfully, but these errors were encountered: