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:
@@ -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.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user