Skip to content

Commit

Permalink
Typed signatures for event handlers.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Patrin <ppatrin@nvidia.com>
  • Loading branch information
pavelpatrin committed Aug 5, 2024
1 parent 70db314 commit 8bfdf04
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion events.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ func (em *events) callTypedHandler(handler reflect.Value, args []any) error {
maxArgsLen := min(len(args), handler.Type().NumIn())
for index := 0; index < maxArgsLen; index++ {
eventArgType := reflect.TypeOf(args[index])
eventArgValue := reflect.ValueOf(args[index])
handlerArgType := handler.Type().In(index)
if !eventArgType.AssignableTo(handlerArgType) {
return fmt.Errorf(
"%w: type '%s' is not assignable to '%s' (index %d)",
HandlerArgTypeMismatchError, eventArgType, handlerArgType, index,
)
}
eventArgValue := reflect.ValueOf(args[index])
handlerInArgs = append(handlerInArgs, eventArgValue)
}

Expand Down

0 comments on commit 8bfdf04

Please sign in to comment.