On Mon, Aug 10, 2020 at 7:08 AM Alvadron <
klos...@gmail.com> wrote:
>
> 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"