On 06/01/2021 21:52, Ivan Majeru wrote:
If I understand right the panic is because the `m := NewMap[string, int]` is a function not a function call and after that you try to assign to this function `m[int]`. This works https://go2goplay.golang.org/p/NOaPH-dJyWd <https://go2goplay.golang.org/p/NOaPH-dJyWd> .

Sure, I know it was wrong, but I was still able to crash the compiler.

Previously I had tried using the (wrong) map-like syntax like this:

    m["foo"] = 123

and this gave a helpful error message (*):

"foo" (untyped string constant) is not a type

which, if you know about generic type parameters makes sense.

So out of interest, I changed it to see what would happen if I *did* put a type there:

    m[int] = 123

... and that caused the panic.

(*) Helpful-ish.  As you say, m is a function, indeed a non-generic one without type parameters. Trying to qualify a such a function with a type doesn't make sense.  Perhaps a better error would be "cannot use type parameters on a non-generic function" or similar.

--
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7c4e6994-63b1-7502-2415-a8d376297ab2%40pobox.com.

Reply via email to