-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.
Milestone
Description
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:
type IntString interface {
type int, string
}
func Sum(type T IntString)(s []T) (result T) {
for _, v := range s {
result += v // this fails even though it's possible to add strings together
}
return
}
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:
func SumString(s []string) (result string) {
for _, v := range s {
result += v
}
return
}
What did you see instead?
It reports the following error:
type checking failed for main
prog.go2:13:3: invalid operation: operator + not defined for result (variable of type T)
Both integers and strings support the +
operator so I would expect this to work.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.