@@ -473,6 +473,24 @@ func TestSingletonOverloadCollision(t *testing.T) {
473473 }
474474}
475475
476+ func TestSingletonOverloadLateBindingCollision (t * testing.T ) {
477+ fn , err := NewFunction ("id" ,
478+ Overload ("id_any" , []* types.Type {types .AnyType }, types .AnyType ,
479+ LateFunctionBinding (),
480+ ),
481+ SingletonUnaryBinding (func (arg ref.Val ) ref.Val {
482+ return arg
483+ }),
484+ )
485+ if err != nil {
486+ t .Fatalf ("NewFunction() failed: %v" , err )
487+ }
488+ _ , err = fn .Bindings ()
489+ if err == nil || ! strings .Contains (err .Error (), "incompatible with late bindings" ) {
490+ t .Errorf ("NewFunction() got %v, wanted incompatible with late bindings" , err )
491+ }
492+ }
493+
476494func TestSingletonUnaryBindingRedefinition (t * testing.T ) {
477495 _ , err := NewFunction ("id" ,
478496 Overload ("id_any" , []* types.Type {types .AnyType }, types .AnyType ),
@@ -592,6 +610,74 @@ func TestOverloadFunctionBindingRedefinition(t *testing.T) {
592610 }
593611}
594612
613+ func TestOverloadFunctionLateBinding (t * testing.T ) {
614+ function , err := NewFunction ("id" ,
615+ Overload ("id_bool" , []* types.Type {types .BoolType }, types .AnyType , LateFunctionBinding (), LateFunctionBinding ()),
616+ )
617+ if err != nil {
618+ t .Fatalf ("NewFunction() failed: %v" , err )
619+ }
620+ if len (function .OverloadDecls ()) != 1 {
621+ t .Fatalf ("NewFunction() got %v, wanted 1 overload" , function .OverloadDecls ())
622+ }
623+ if ! function .OverloadDecls ()[0 ].HasLateBinding () {
624+ t .Errorf ("overload %v did not have a late binding" , function .OverloadDecls ()[0 ])
625+ }
626+ }
627+
628+ func TestOverloadFunctionMixLateAndNonLateBinding (t * testing.T ) {
629+ _ , err := NewFunction ("id" ,
630+ Overload ("id_bool" , []* types.Type {types .BoolType }, types .AnyType , LateFunctionBinding ()),
631+ Overload ("id_int" , []* types.Type {types .IntType }, types .AnyType ),
632+ )
633+ if err == nil || ! strings .Contains (err .Error (), "cannot mix late and non-late bindings" ) {
634+ t .Errorf ("NewCustomEnv() got %v, wanted cannot mix late and non-late bindings" , err )
635+ }
636+ }
637+
638+ func TestOverloadFunctionBindingWithLateBinding (t * testing.T ) {
639+ _ , err := NewFunction ("id" ,
640+ Overload ("id_bool" , []* types.Type {types .BoolType }, types .AnyType , FunctionBinding (func (args ... ref.Val ) ref.Val {
641+ return args [0 ]
642+ }), LateFunctionBinding ()),
643+ )
644+ if err == nil || ! strings .Contains (err .Error (), "already has a binding" ) {
645+ t .Errorf ("NewCustomEnv() got %v, wanted already has a binding" , err )
646+ }
647+ }
648+
649+ func TestOverloadFunctionLateBindingWithBinding (t * testing.T ) {
650+ _ , err := NewFunction ("id" ,
651+ Overload ("id_bool" , []* types.Type {types .BoolType }, types .AnyType , LateFunctionBinding (),
652+ FunctionBinding (func (args ... ref.Val ) ref.Val {
653+ return args [0 ]
654+ })),
655+ )
656+ if err == nil || ! strings .Contains (err .Error (), "already has a late binding" ) {
657+ t .Errorf ("NewCustomEnv() got %v, wanted already has a late binding" , err )
658+ }
659+
660+ _ , err = NewFunction ("id" ,
661+ Overload ("id_bool" , []* types.Type {types .BoolType }, types .AnyType , LateFunctionBinding (),
662+ UnaryBinding (func (arg ref.Val ) ref.Val {
663+ return arg
664+ })),
665+ )
666+ if err == nil || ! strings .Contains (err .Error (), "already has a late binding" ) {
667+ t .Errorf ("NewCustomEnv() got %v, wanted already has a late binding" , err )
668+ }
669+
670+ _ , err = NewFunction ("id" ,
671+ Overload ("id_bool" , []* types.Type {types .BoolType , types .BoolType }, types .AnyType , LateFunctionBinding (),
672+ BinaryBinding (func (arg1 ref.Val , arg2 ref.Val ) ref.Val {
673+ return arg1
674+ })),
675+ )
676+ if err == nil || ! strings .Contains (err .Error (), "already has a late binding" ) {
677+ t .Errorf ("NewCustomEnv() got %v, wanted already has a late binding" , err )
678+ }
679+ }
680+
595681func TestOverloadIsNonStrict (t * testing.T ) {
596682 fn , err := NewFunction ("getOrDefault" ,
597683 MemberOverload ("get" ,
0 commit comments