From 8fa18cd61b6fc6192662f20890c2dd5bfd998eb0 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 4 Apr 2020 10:02:48 +0200 Subject: [PATCH] enforce dynamic signature check: no input struct allowed when no input is specified --- dynamic/errors.go | 3 +++ dynamic/spec.go | 3 +++ dynamic/spec_test.go | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dynamic/errors.go b/dynamic/errors.go index f8260c3..9467bcf 100644 --- a/dynamic/errors.go +++ b/dynamic/errors.go @@ -17,6 +17,9 @@ const ErrNoServiceForHandler = cerr("no service found for this handler") // ErrMissingHandlerArgumentParam - missing params arguments for handler const ErrMissingHandlerArgumentParam = cerr("missing handler argument : parameter struct") +// ErrUnexpectedInput - input argument is not expected +const ErrUnexpectedInput = cerr("unexpected input struct") + // ErrMissingHandlerOutput - missing output for handler const ErrMissingHandlerOutput = cerr("handler must have at least 1 output") diff --git a/dynamic/spec.go b/dynamic/spec.go index 9e0871e..ee6fd06 100644 --- a/dynamic/spec.go +++ b/dynamic/spec.go @@ -44,6 +44,9 @@ func (s spec) checkInput(fnv reflect.Value) error { // no input -> ok if len(s.Input) == 0 { + if fnt.NumIn() > 0 { + return ErrUnexpectedInput + } return nil } diff --git a/dynamic/spec_test.go b/dynamic/spec_test.go index 535d9e3..0ce92bc 100644 --- a/dynamic/spec_test.go +++ b/dynamic/spec_test.go @@ -21,11 +21,11 @@ func TestInputCheck(t *testing.T) { Fn: func() {}, Err: nil, }, - // func can have any arguments if not specified + // func must have noarguments if none specified { Input: map[string]reflect.Type{}, Fn: func(int, string) {}, - Err: nil, + Err: ErrUnexpectedInput, }, // missing input struct in func {