Skip to content

Commit

Permalink
ua: do not panic if the same extension object is registered multiple …
Browse files Browse the repository at this point in the history
…times
  • Loading branch information
magiconair committed May 6, 2022
1 parent 71397d5 commit 2349f0c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ua/typereg.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *TypeRegistry) Lookup(v interface{}) *NodeID {

// Register adds a new type to the registry.
//
// If the id is already registered the function returns an error.
// If the id is already registered as a different type the function returns an error.
//
// Register panics if id is nil.
func (r *TypeRegistry) Register(id *NodeID, v interface{}) error {
Expand All @@ -84,8 +84,8 @@ func (r *TypeRegistry) Register(id *NodeID, v interface{}) error {
typ := reflect.TypeOf(v)
ids := id.String()

if r.types[ids] != nil {
return errors.Errorf("%s is already registered", id)
if cur := r.types[ids]; cur != nil && cur != typ {
return errors.Errorf("%s is already registered as %v", id, cur)
}
r.types[ids] = typ

Expand Down

0 comments on commit 2349f0c

Please sign in to comment.