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
cmd/go2go: adding strings together is not defined #39623
Comments
There seems to be some interaction with the package main
import "fmt"
func main() {
fmt.Println(Add("Hello", ", world!"))
}
func Add(type T addable)(x, y T) T {
return x + y
}
type addable interface {
type string
}
But this does not https://go2goplay.golang.org/p/Ksywhb4RF6x: package main
import "fmt"
func main() {
fmt.Println(Add("Hello", ", world!"))
}
func Add(type T addable)(x, y T) T {
return x + y
}
type addable interface {
type string, int
}
|
Yes, this is a bug in the type checker; thanks for reporting. One of the more complicated things to get right is computing the subset of operations that are valid for all types of a type list. In this case it should have been easy, but obviously there's a bug somewhere. |
Change https://golang.org/cl/238359 mentions this issue: |
…tion See also https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562 for the analogous problem for another predicate. Fixes #39623. Change-Id: I39efcb07c337691eb202de166e2cb8d6b5d5ee18 Reviewed-on: https://go-review.googlesource.com/c/go/+/238359 Reviewed-by: Robert Griesemer <gri@golang.org>
This is now fixed in dev.go2go. Will be fixed in the playground as soon as it's updated. |
FWIW I can confirm that it works in playground now. |
I've been experimenting a bit with generics at https://go2goplay.golang.org/ and I think I found a bug.
What did you do?
See: https://go2goplay.golang.org/p/efS6x6s-9NI
I tried concatenating a string:
What did you expect to see?
Strings can be added (concatenated) together, so I would expect it to also work when using generics.
Specialized variant of the same function, which does compile:
What did you see instead?
It reports the following error:
Both integers and strings support the
+
operator so I would expect this to work.The text was updated successfully, but these errors were encountered: