瀏覽代碼

* use new compare_rettype() to compare the return types of functions to decide whether they can be added as overloads so that operator overloads that have (different) generic types as return values are treated as different
+ added tests

Sven/Sarah Barth 3 天之前
父節點
當前提交
a3ae828b65
共有 3 個文件被更改,包括 57 次插入1 次删除
  1. 1 1
      compiler/pparautl.pas
  2. 31 0
      tests/test/tgeneric126.pp
  3. 25 0
      tests/test/tgeneric127.pp

+ 1 - 1
compiler/pparautl.pas

@@ -817,7 +817,7 @@ implementation
       function equal_signature(fwpd,currpd:tprocdef;out sameparas,sameret:boolean):boolean;
         begin
           sameparas:=compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv])=te_exact;
-          sameret:=compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact;
+          sameret:=compare_rettype(fwpd.returndef,currpd.returndef)=te_exact;
           result:=sameparas and sameret;
         end;
 

+ 31 - 0
tests/test/tgeneric126.pp

@@ -0,0 +1,31 @@
+{ %NORUN }
+
+program tgeneric126;
+
+{$mode delphi}
+
+type
+  TTest<S, T> = record
+    class operator Implicit(const aArg: TTest<S, T>): T;
+    class operator Implicit(const aArg: TTest<S, T>): TArray<T>;
+    class operator Implicit(const aArg: TTest<S, T>): S;
+  end;
+
+class operator TTest<S, T>.Implicit(const aArg: TTest<S, T>): T;
+begin
+
+end;
+
+class operator TTest<S, T>.Implicit(const aArg: TTest<S, T>): TArray<T>;
+begin
+
+end;
+
+class operator TTest<S, T>.Implicit(const aArg: TTest<S, T>): S;
+begin
+
+end;
+
+begin
+
+end.

+ 25 - 0
tests/test/tgeneric127.pp

@@ -0,0 +1,25 @@
+{ %FAIL }
+
+program tgeneric127;
+
+{$mode delphi}
+
+type
+  TTest<T> = record
+    class operator Implicit(const aArg: TTest<T>): T;
+    class operator Implicit(const aArg: TTest<T>): T;
+  end;
+
+class operator TTest<T>.Implicit(const aArg: TTest<T>): T;
+begin
+
+end;
+
+class operator TTest<T>.Implicit(const aArg: TTest<T>): T;
+begin
+
+end;
+
+begin
+
+end.