Browse Source

* fix #40876: correctly check for generic constant parameters without concrete value
+ added test

Sven/Sarah Barth 7 months ago
parent
commit
ead882f58d
2 changed files with 31 additions and 1 deletions
  1. 2 1
      compiler/pgenutil.pas
  2. 29 0
      tests/webtbs/tw40876.pp

+ 2 - 1
compiler/pgenutil.pas

@@ -1688,7 +1688,8 @@ uses
           result:=False;
           if adef.genericparas<>nil then
             for i:=0 to adef.genericparas.Count-1 do
-              if sp_generic_para in tsym(adef.genericparas[i]).symoptions then
+              if ((tsym(adef.genericparas[i]).typ=typesym) and (sp_generic_para in tsym(adef.genericparas[i]).symoptions)) or
+                  ((tsym(adef.genericparas[i]).typ=constsym) and not (sp_generic_const in tsym(adef.genericparas[i]).symoptions)) then
                 exit(true);
         end;
 

+ 29 - 0
tests/webtbs/tw40876.pp

@@ -0,0 +1,29 @@
+{ %NORUN }
+
+program tw40876;
+
+{$Mode Delphi}
+
+uses
+    SysUtils;
+
+type
+    TTest<const A: UInt64> = record
+    public
+        function ToString(B: UInt64): UnicodeString;
+    end;
+
+// There should be at least one method for linking to fail
+function TTest<A>.ToString(B: UInt64): UnicodeString;
+begin
+    Result := (A + B).ToString;
+end;
+
+type
+    TMyTest = TTest<1234>;
+
+var A: TMyTest;
+begin
+    WriteLn(A.ToString(23456));
+end.
+