@@ -484,6 +484,11 @@ cannot use int to get an element from map[string]interface {} (1:10)
484
484
invalid operation: + (mismatched types int and string) (1:13)
485
485
| 1 /* one */ + "2"
486
486
| ............^
487
+
488
+ FuncTyped(42)
489
+ cannot use int as argument (type string) to call FuncTyped (1:11)
490
+ | FuncTyped(42)
491
+ | ..........^
487
492
`
488
493
489
494
func TestCheck_error (t * testing.T ) {
@@ -893,3 +898,38 @@ func TestCheck_dont_panic_on_nil_arguments_for_builtins(t *testing.T) {
893
898
})
894
899
}
895
900
}
901
+
902
+ func TestCheck_do_not_override_params_for_functions (t * testing.T ) {
903
+ env := map [string ]interface {}{
904
+ "foo" : func (p string ) string {
905
+ return "foo"
906
+ },
907
+ }
908
+ config := conf .New (env )
909
+ expr .Function (
910
+ "bar" ,
911
+ func (p ... interface {}) (interface {}, error ) {
912
+ return p [0 ].(string ), nil
913
+ },
914
+ new (func (string ) string ),
915
+ )(config )
916
+ config .Check ()
917
+
918
+ t .Run ("func from env" , func (t * testing.T ) {
919
+ tree , err := parser .Parse ("foo(1)" )
920
+ require .NoError (t , err )
921
+
922
+ _ , err = checker .Check (tree , config )
923
+ require .Error (t , err )
924
+ require .Contains (t , err .Error (), "cannot use int as argument" )
925
+ })
926
+
927
+ t .Run ("func from function" , func (t * testing.T ) {
928
+ tree , err := parser .Parse ("bar(1)" )
929
+ require .NoError (t , err )
930
+
931
+ _ , err = checker .Check (tree , config )
932
+ require .Error (t , err )
933
+ require .Contains (t , err .Error (), "cannot use int as argument" )
934
+ })
935
+ }
0 commit comments