@@ -51,19 +51,6 @@ func (c *Config) WithEnv(env interface{}) {
5151
5252func (c * Config ) Operator (operator string , fns ... string ) {
5353 c .Operators [operator ] = append (c .Operators [operator ], fns ... )
54- for _ , fn := range fns {
55- fnType , ok := c .Types [fn ]
56- if ! ok || fnType .Type .Kind () != reflect .Func {
57- panic (fmt .Errorf ("function %s for %s operator does not exist in the environment" , fn , operator ))
58- }
59- requiredNumIn := 2
60- if fnType .Method {
61- requiredNumIn = 3 // As first argument of method is receiver.
62- }
63- if fnType .Type .NumIn () != requiredNumIn || fnType .Type .NumOut () != 1 {
64- panic (fmt .Errorf ("function %s for %s operator does not have a correct signature" , fn , operator ))
65- }
66- }
6754}
6855
6956func (c * Config ) ConstExpr (name string ) {
@@ -76,3 +63,21 @@ func (c *Config) ConstExpr(name string) {
7663 }
7764 c .ConstFns [name ] = fn
7865}
66+
67+ func (c * Config ) Check () {
68+ for operator , fns := range c .Operators {
69+ for _ , fn := range fns {
70+ fnType , ok := c .Types [fn ]
71+ if ! ok || fnType .Type .Kind () != reflect .Func {
72+ panic (fmt .Errorf ("function %s for %s operator does not exist in the environment" , fn , operator ))
73+ }
74+ requiredNumIn := 2
75+ if fnType .Method {
76+ requiredNumIn = 3 // As first argument of method is receiver.
77+ }
78+ if fnType .Type .NumIn () != requiredNumIn || fnType .Type .NumOut () != 1 {
79+ panic (fmt .Errorf ("function %s for %s operator does not have a correct signature" , fn , operator ))
80+ }
81+ }
82+ }
83+ }
0 commit comments