Hi all,

In this code, the SetMapIndex line panics in Go <1.18, but it no longer
panics in Go 1.18:

    type CustomString string
    m := reflect.ValueOf(map[CustomString]int{})
    m.SetMapIndex(reflect.ValueOf("key"), reflect.ValueOf(0))

The panic ("value of type string is not assignable to type CustomString")
appears to be prevented in Go 1.18 because reflect implicitly converts
string -> CustomString, which Go <1.18 doesn't do.

I had 2 questions:

    - Is it possible to get this implicit conversion behavior in earlier
versions of Go? Specifically, I'm using Go 1.16 + the firestore package,
and I'd like to use custom string types as map keys.

    - Is this change discussed anywhere?

Thanks!

David

-- 
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/CACLqBF1Y4MzwGZBxAGEnVmXR%3D_%2BOSUy%2B4dR%3DxP2%3DfYB03JZ%3DEA%40mail.gmail.com.

Reply via email to