Browse Source

* a function can't be used to implicitely specialize a specialized procedure variable parameter and vice versa
+ added test

Sven/Sarah Barth 3 years ago
parent
commit
c0fa45dc92
2 changed files with 26 additions and 0 deletions
  1. 5 0
      compiler/pgenutil.pas
  2. 21 0
      tests/test/timpfuncspez37.pp

+ 5 - 0
compiler/pgenutil.pas

@@ -945,6 +945,11 @@ uses
           if target_proc.paras.count<>caller_proc.paras.count then
             exit;
 
+          { a mixture of functions and procedures is not allowed }
+          if (not assigned(target_proc.returndef) or is_void(target_proc.returndef)) xor
+              (not assigned(caller_proc.returndef) or is_void(caller_proc.returndef)) then
+            exit;
+
           { reject generics with constants }
           for i:=0 to target_proc.genericdef.genericparas.count-1 do
             if tsym(target_proc.genericdef.genericparas[i]).typ=constsym then

+ 21 - 0
tests/test/timpfuncspez37.pp

@@ -0,0 +1,21 @@
+{ %FAIL }
+
+program timpfuncspez37;
+
+{$mode objfpc}
+{$modeswitch implicitfunctionspecialization}
+
+type
+  generic TTestFunc<T> = procedure(aArg1: T);
+
+generic procedure DoTest<T>(aArg: specialize TTestFunc<T>);
+begin
+end;
+
+function TestFunc(aArg1: LongInt): LongInt;
+begin
+end;
+
+begin
+  DoTest(@TestFunc);
+end.