瀏覽代碼

* in case of an implicit specialization ensure that the symbol of the generic is indeed considered as used once the final implicit specialization has been picked
+ added test

Sven/Sarah Barth 3 年之前
父節點
當前提交
74f9523806
共有 2 個文件被更改,包括 26 次插入0 次删除
  1. 8 0
      compiler/ncal.pas
  2. 18 0
      tests/webtbs/tw39684.pp

+ 8 - 0
compiler/ncal.pas

@@ -3881,6 +3881,14 @@ implementation
                 { add reference to corresponding procsym; may not be the one
                   originally found/passed to the constructor because of overloads }
                 addsymref(tprocdef(procdefinition).procsym,procdefinition);
+
+                { ensure that the generic is considered as used as for an
+                  implicit specialization must only be called after the final
+                  overload was picked }
+                if assigned(tprocdef(procdefinition).genericdef) and
+                    assigned(tprocdef(tprocdef(procdefinition).genericdef).procsym) and
+                    (tprocdef(tprocdef(procdefinition).genericdef).procsym.refs=0) then
+                  addsymref(tprocdef(tprocdef(procdefinition).genericdef).procsym);
               end;
 
             { add needed default parameters }

+ 18 - 0
tests/webtbs/tw39684.pp

@@ -0,0 +1,18 @@
+{ %OPT=-vh }
+
+program tw39684;
+{$mode objfpc}
+{$ModeSwitch ImplicitFunctionSpecialization }
+
+{$warn 5028 error}
+
+generic function Add<T>(aArg1, aArg2: T): T;
+begin
+  Result := aArg1 + aArg2;
+end;
+
+begin
+  //specialize Add<byte>(byte(0), byte(0));  // No Hint
+  Add(byte(0), byte(0));
+end.
+