addrs: ModuleInstance and AbsResourceInstance are UniqueKeyers

Since these address types are not directly comparable themselves, we use
an unexported named type around the string representation, whereby the
special type can avoid any ambiguity between string representations of
different types and thus each type only needs to worry about possible
ambiguity of its _own_ string representation.
pull/29167/head
Martin Atkins 5 years ago
parent f3a57db293
commit cd06572c4f

@ -275,6 +275,14 @@ func (m ModuleInstance) String() string {
return buf.String()
}
type moduleInstanceKey string
func (m ModuleInstance) UniqueKey() UniqueKey {
return moduleInstanceKey(m.String())
}
func (mk moduleInstanceKey) uniqueKeySigil() {}
// Equal returns true if the receiver and the given other value
// contains the exact same parts.
func (m ModuleInstance) Equal(o ModuleInstance) bool {

@ -292,6 +292,14 @@ func (r AbsResourceInstance) Less(o AbsResourceInstance) bool {
}
}
type absResourceInstanceKey string
func (r AbsResourceInstance) UniqueKey() UniqueKey {
return absResourceInstanceKey(r.String())
}
func (r absResourceInstanceKey) uniqueKeySigil() {}
func (r AbsResourceInstance) absMoveableSigil() {
// AbsResourceInstance is moveable
}

@ -46,6 +46,14 @@ func TestUniqueKeyer(t *testing.T) {
},
Key: IntKey(1),
},
RootModuleInstance,
RootModuleInstance.Child("foo", NoKey),
RootModuleInstance.ResourceInstance(
DataResourceMode,
"boop",
"beep",
NoKey,
),
Self,
}

Loading…
Cancel
Save