From 883cc6d697a33d1e02e5cb2bfcc1eec8343e938b Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Tue, 31 May 2022 22:45:43 +0200 Subject: [PATCH] + add tests that ensure that the overload selection works correctly when functions, methods or nested functions are assigned when overloads for function references are involved as well --- tests/test/tfuncref33.pp | 159 +++++++++++++++++++++++++++++++++++++++ tests/test/tfuncref34.pp | 159 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 318 insertions(+) create mode 100644 tests/test/tfuncref33.pp create mode 100644 tests/test/tfuncref34.pp diff --git a/tests/test/tfuncref33.pp b/tests/test/tfuncref33.pp new file mode 100644 index 0000000000..349525029e --- /dev/null +++ b/tests/test/tfuncref33.pp @@ -0,0 +1,159 @@ +program tfuncref33; + +{$mode objfpc} +{$modeswitch functionreferences} +{$modeswitch nestedprocvars} + +type + TProcVar = procedure; + TMethodVar = procedure of object; + TProcRef = reference to procedure; + TNestedVar = procedure is nested; + + TTest = class + function Test1(aArg: TProcVar): LongInt; + function Test1(aArg: TProcRef): LongInt; + + function Test2(aArg: TMethodVar): LongInt; + function Test2(aArg: TProcRef): LongInt; + + function Test3(aArg: TNestedVar): LongInt; + function Test3(aArg: TProcRef): LongInt; + + function Test4(aArg: TProcVar): LongInt; + function Test4(aArg: TMethodVar): LongInt; + function Test4(aArg: TProcRef): LongInt; + + function Test5(aArg: TProcVar): LongInt; + function Test5(aArg: TMethodVar): LongInt; + function Test5(aArg: TNestedVar): LongInt; + function Test5(aArg: TProcRef): LongInt; + + procedure TestMethod; + + procedure DoTest; + end; + +procedure TestProc; +begin +end; + +function TTest.Test1(aArg: TProcVar): LongInt; +begin + Result := 1; +end; +function TTest.Test1(aArg: TProcRef): LongInt; +begin + Result := 2; +end; +function TTest.Test2(aArg: TMethodVar): LongInt; +begin + Result := 3; +end; +function TTest.Test2(aArg: TProcRef): LongInt; +begin + Result := 4; +end; +function TTest.Test3(aArg: TNestedVar): LongInt; +begin + Result := 5; +end; +function TTest.Test3(aArg: TProcRef): LongInt; +begin + Result := 6; +end; +function TTest.Test4(aArg: TProcVar): LongInt; +begin + Result := 7; +end; +function TTest.Test4(aArg: TMethodVar): LongInt; +begin + Result := 8; +end; +function TTest.Test4(aArg: TProcRef): LongInt; +begin + Result := 9; +end; +function TTest.Test5(aArg: TProcVar): LongInt; +begin + Result := 10; +end; +function TTest.Test5(aArg: TMethodVar): LongInt; +begin + Result := 11; +end; +function TTest.Test5(aArg: TNestedVar): LongInt; +begin + Result := 12; +end; +function TTest.Test5(aArg: TProcRef): LongInt; +begin + Result := 13; +end; + +procedure TTest.TestMethod; +begin +end; + +procedure TTest.DoTest; + + procedure NestedProc; + begin + end; + +var + f: TProcRef; +begin + if Test1(@TestProc) <> 1 then + Halt(1); + if Test1(@TestMethod) <> 2 then + Halt(2); + if Test1(@NestedProc) <> 2 then + Halt(3); + if Test1(f) <> 2 then + Halt(4); + + if Test2(@TestProc) <> 4 then + Halt(5); + if Test2(@TestMethod) <> 3 then + Halt(6); + if Test2(@NestedProc) <> 4 then + Halt(7); + if Test2(f) <> 4 then + Halt(8); + + if Test3(@TestProc) <> 5 then + Halt(9); + if Test3(@TestMethod) <> 6 then + Halt(10); + if Test3(@NestedProc) <> 5 then + Halt(11); + if Test3(f) <> 6 then + Halt(12); + + if Test4(@TestProc) <> 7 then + Halt(13); + if Test4(@TestMethod) <> 8 then + Halt(14); + if Test4(@NestedProc) <> 9 then + Halt(15); + if Test4(f) <> 9 then + Halt(16); + + if Test5(@TestProc) <> 10 then + Halt(17); + if Test5(@TestMethod) <> 11 then + Halt(18); + if Test5(@NestedProc) <> 12 then + Halt(19); + if Test5(f) <> 13 then + Halt(20); +end; + +var + t: TTest; +begin + t := TTest.Create; + t.DoTest; + t.Free; +end. diff --git a/tests/test/tfuncref34.pp b/tests/test/tfuncref34.pp new file mode 100644 index 0000000000..f440b35555 --- /dev/null +++ b/tests/test/tfuncref34.pp @@ -0,0 +1,159 @@ +program tfuncref34; + +{$mode delphi} +{$modeswitch functionreferences} +{$modeswitch nestedprocvars} + +type + TProcVar = procedure; + TMethodVar = procedure of object; + TProcRef = reference to procedure; + TNestedVar = procedure is nested; + + TTest = class + function Test1(aArg: TProcVar): LongInt; overload; + function Test1(aArg: TProcRef): LongInt; overload; + + function Test2(aArg: TMethodVar): LongInt; overload; + function Test2(aArg: TProcRef): LongInt; overload; + + function Test3(aArg: TNestedVar): LongInt; overload; + function Test3(aArg: TProcRef): LongInt; overload; + + function Test4(aArg: TProcVar): LongInt; overload; + function Test4(aArg: TMethodVar): LongInt; overload; + function Test4(aArg: TProcRef): LongInt; overload; + + function Test5(aArg: TProcVar): LongInt; overload; + function Test5(aArg: TMethodVar): LongInt; overload; + function Test5(aArg: TNestedVar): LongInt; overload; + function Test5(aArg: TProcRef): LongInt; overload; + + procedure TestMethod; + + procedure DoTest; + end; + +procedure TestProc; +begin +end; + +function TTest.Test1(aArg: TProcVar): LongInt; +begin + Result := 1; +end; +function TTest.Test1(aArg: TProcRef): LongInt; +begin + Result := 2; +end; +function TTest.Test2(aArg: TMethodVar): LongInt; +begin + Result := 3; +end; +function TTest.Test2(aArg: TProcRef): LongInt; +begin + Result := 4; +end; +function TTest.Test3(aArg: TNestedVar): LongInt; +begin + Result := 5; +end; +function TTest.Test3(aArg: TProcRef): LongInt; +begin + Result := 6; +end; +function TTest.Test4(aArg: TProcVar): LongInt; +begin + Result := 7; +end; +function TTest.Test4(aArg: TMethodVar): LongInt; +begin + Result := 8; +end; +function TTest.Test4(aArg: TProcRef): LongInt; +begin + Result := 9; +end; +function TTest.Test5(aArg: TProcVar): LongInt; +begin + Result := 10; +end; +function TTest.Test5(aArg: TMethodVar): LongInt; +begin + Result := 11; +end; +function TTest.Test5(aArg: TNestedVar): LongInt; +begin + Result := 12; +end; +function TTest.Test5(aArg: TProcRef): LongInt; +begin + Result := 13; +end; + +procedure TTest.TestMethod; +begin +end; + +procedure TTest.DoTest; + + procedure NestedProc; + begin + end; + +var + f: TProcRef; +begin + if Test1(TestProc) <> 1 then + Halt(1); + if Test1(TestMethod) <> 2 then + Halt(2); + if Test1(NestedProc) <> 2 then + Halt(3); + if Test1(f) <> 2 then + Halt(4); + + if Test2(TestProc) <> 4 then + Halt(5); + if Test2(TestMethod) <> 3 then + Halt(6); + if Test2(NestedProc) <> 4 then + Halt(7); + if Test2(f) <> 4 then + Halt(8); + + if Test3(TestProc) <> 5 then + Halt(9); + if Test3(TestMethod) <> 6 then + Halt(10); + if Test3(NestedProc) <> 5 then + Halt(11); + if Test3(f) <> 6 then + Halt(12); + + if Test4(TestProc) <> 7 then + Halt(13); + if Test4(TestMethod) <> 8 then + Halt(14); + if Test4(NestedProc) <> 9 then + Halt(15); + if Test4(f) <> 9 then + Halt(16); + + if Test5(TestProc) <> 10 then + Halt(17); + if Test5(TestMethod) <> 11 then + Halt(18); + if Test5(NestedProc) <> 12 then + Halt(19); + if Test5(f) <> 13 then + Halt(20); +end; + +var + t: TTest; +begin + t := TTest.Create; + t.DoTest; + t.Free; +end.