Discovered interesting case in map key checking.

Using interfaces as a map's key type can cause some things that were otherwise
compile-time checks to be pushed off into runtime checks instead.
This is a pretty major "caveat emptor" if you use interface-keyed maps.
This commit is contained in:
Eric Myhre
2018-08-24 12:16:52 +02:00
parent c724ad0d22
commit b4ab25ffda

View File

@@ -15,6 +15,8 @@ import (
var _ Cid = CidStruct{}
//var _ map[CidStruct]struct{} = nil // Will not compile! See struct def docs.
//var _ map[Cid]struct{} = map[Cid]struct{}{CidStruct{}: struct{}{}} // Legal to compile...
// but you'll get panics: "runtime error: hash of unhashable type cid.CidStruct"
// CidStruct represents a CID in a struct format.
//