enforce dynamic signature check: no input struct allowed when no input is specified

This commit is contained in:
Adrien Marquès 2020-04-04 10:02:48 +02:00
parent db4429b329
commit 8fa18cd61b
Signed by: xdrm-brackets
GPG Key ID: D75243CA236D825E
3 changed files with 8 additions and 2 deletions

View File

@ -17,6 +17,9 @@ const ErrNoServiceForHandler = cerr("no service found for this handler")
// ErrMissingHandlerArgumentParam - missing params arguments for handler // ErrMissingHandlerArgumentParam - missing params arguments for handler
const ErrMissingHandlerArgumentParam = cerr("missing handler argument : parameter struct") 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 // ErrMissingHandlerOutput - missing output for handler
const ErrMissingHandlerOutput = cerr("handler must have at least 1 output") const ErrMissingHandlerOutput = cerr("handler must have at least 1 output")

View File

@ -44,6 +44,9 @@ func (s spec) checkInput(fnv reflect.Value) error {
// no input -> ok // no input -> ok
if len(s.Input) == 0 { if len(s.Input) == 0 {
if fnt.NumIn() > 0 {
return ErrUnexpectedInput
}
return nil return nil
} }

View File

@ -21,11 +21,11 @@ func TestInputCheck(t *testing.T) {
Fn: func() {}, Fn: func() {},
Err: nil, Err: nil,
}, },
// func can have any arguments if not specified // func must have noarguments if none specified
{ {
Input: map[string]reflect.Type{}, Input: map[string]reflect.Type{},
Fn: func(int, string) {}, Fn: func(int, string) {},
Err: nil, Err: ErrUnexpectedInput,
}, },
// missing input struct in func // missing input struct in func
{ {