The type of map keys in Go should be comparable. As you haven't specified
any restriction to the type parameters, it doesn't compile because Go
doesn't know whether K and V are comparable.
If you add the restriction "comparable", then it compiles:
type BiMap[type V, K comparable] struct {
forward map[K]V
reverse map[V]K
}
PD: It is true that the error could be more informative. Right now we get:
type checking failed for main
prog.go2:13:14: invalid map key type K
prog.go2:14:14: invalid map key type V
Not sure if it is possible but, ideally, the message should say something
like "Invalid mp key type K: it is not comparable"
El lunes, 10 de agosto de 2020 a las 13:49:48 UTC+1, [email protected]
escribió:
> This is invalid:
>
> type BiMap[type V, K] struct {
> forward map[K]V
> reverse map[V]K
> }
>
> How do I specify an interface constraint for V,K such that this is valid?
> Is that possible at all?
>
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/fea594db-a877-45a1-913b-46bb427f8795n%40googlegroups.com.