@@ -10,7 +10,6 @@ import (
1010 "github.com/expr-lang/expr/conf"
1111 "github.com/expr-lang/expr/file"
1212 "github.com/expr-lang/expr/parser"
13- "github.com/expr-lang/expr/vm"
1413)
1514
1615func Check (tree * parser.Tree , config * conf.Config ) (t reflect.Type , err error ) {
@@ -374,11 +373,10 @@ func (v *checker) BinaryNode(node *ast.BinaryNode) (reflect.Type, info) {
374373
375374 case "matches" :
376375 if s , ok := node .Right .(* ast.StringNode ); ok {
377- r , err := regexp .Compile (s .Value )
376+ _ , err := regexp .Compile (s .Value )
378377 if err != nil {
379378 return v .error (node , err .Error ())
380379 }
381- node .Regexp = r
382380 }
383381 if isString (l ) && isString (r ) {
384382 return boolType , info {}
@@ -549,7 +547,6 @@ func (v *checker) functionReturnType(node *ast.CallNode) (reflect.Type, info) {
549547 fn , fnInfo := v .visit (node .Callee )
550548
551549 if fnInfo .fn != nil {
552- node .Func = fnInfo .fn
553550 return v .checkFunction (fnInfo .fn , node , node .Arguments )
554551 }
555552
@@ -571,33 +568,13 @@ func (v *checker) functionReturnType(node *ast.CallNode) (reflect.Type, info) {
571568 case reflect .Interface :
572569 return anyType , info {}
573570 case reflect .Func :
574- inputParamsCount := 1 // for functions
575- if fnInfo .method {
576- inputParamsCount = 2 // for methods
577- }
578- // TODO: Deprecate OpCallFast and move fn(...any) any to TypedFunc list.
579- // To do this we need add support for variadic arguments in OpCallTyped.
580- if ! isAny (fn ) &&
581- fn .IsVariadic () &&
582- fn .NumIn () == inputParamsCount &&
583- fn .NumOut () == 1 &&
584- fn .Out (0 ).Kind () == reflect .Interface {
585- rest := fn .In (fn .NumIn () - 1 ) // function has only one param for functions and two for methods
586- if kind (rest ) == reflect .Slice && rest .Elem ().Kind () == reflect .Interface {
587- node .Fast = true
588- }
589- }
590-
591571 outType , err := v .checkArguments (fnName , fn , fnInfo .method , node .Arguments , node )
592572 if err != nil {
593573 if v .err == nil {
594574 v .err = err
595575 }
596576 return anyType , info {}
597577 }
598-
599- v .findTypedFunc (node , fn , fnInfo .method )
600-
601578 return outType , info {}
602579 }
603580 return v .error (node , "%v is not callable" , fn )
@@ -883,7 +860,13 @@ func (v *checker) checkFunction(f *ast.Function, node ast.Node, arguments []ast.
883860 return v .error (node , "no matching overload for %v" , f .Name )
884861}
885862
886- func (v * checker ) checkArguments (name string , fn reflect.Type , method bool , arguments []ast.Node , node ast.Node ) (reflect.Type , * file.Error ) {
863+ func (v * checker ) checkArguments (
864+ name string ,
865+ fn reflect.Type ,
866+ method bool ,
867+ arguments []ast.Node ,
868+ node ast.Node ,
869+ ) (reflect.Type , * file.Error ) {
887870 if isAny (fn ) {
888871 return anyType , nil
889872 }
@@ -1122,44 +1105,3 @@ func (v *checker) PairNode(node *ast.PairNode) (reflect.Type, info) {
11221105 v .visit (node .Value )
11231106 return nilType , info {}
11241107}
1125-
1126- func (v * checker ) findTypedFunc (node * ast.CallNode , fn reflect.Type , method bool ) {
1127- // OnCallTyped doesn't work for functions with variadic arguments,
1128- // and doesn't work named function, like `type MyFunc func() int`.
1129- // In PkgPath() is an empty string, it's unnamed function.
1130- if ! fn .IsVariadic () && fn .PkgPath () == "" {
1131- fnNumIn := fn .NumIn ()
1132- fnInOffset := 0
1133- if method {
1134- fnNumIn --
1135- fnInOffset = 1
1136- }
1137- funcTypes:
1138- for i := range vm .FuncTypes {
1139- if i == 0 {
1140- continue
1141- }
1142- typed := reflect .ValueOf (vm .FuncTypes [i ]).Elem ().Type ()
1143- if typed .Kind () != reflect .Func {
1144- continue
1145- }
1146- if typed .NumOut () != fn .NumOut () {
1147- continue
1148- }
1149- for j := 0 ; j < typed .NumOut (); j ++ {
1150- if typed .Out (j ) != fn .Out (j ) {
1151- continue funcTypes
1152- }
1153- }
1154- if typed .NumIn () != fnNumIn {
1155- continue
1156- }
1157- for j := 0 ; j < typed .NumIn (); j ++ {
1158- if typed .In (j ) != fn .In (j + fnInOffset ) {
1159- continue funcTypes
1160- }
1161- }
1162- node .Typed = i
1163- }
1164- }
1165- }
0 commit comments