Przeglądaj źródła

Fix for Mantis #21538.

* defcmp.pas, compare_defs_ext: 
  use the new genericparas list to check whether two specializations of the same generic can be considered equal
+ added test

git-svn-id: trunk@22454 -
svenbarth 13 lat temu
rodzic
commit
2414c55ca0
4 zmienionych plików z 67 dodań i 0 usunięć
  1. 2 0
      .gitattributes
  2. 29 0
      compiler/defcmp.pas
  3. 19 0
      tests/webtbs/tw21538.pp
  4. 17 0
      tests/webtbs/uw21538.pp

+ 2 - 0
.gitattributes

@@ -12808,6 +12808,7 @@ tests/webtbs/tw21443.pp svneol=native#text/plain
 tests/webtbs/tw2145.pp svneol=native#text/plain
 tests/webtbs/tw21457.pp svneol=native#text/pascal
 tests/webtbs/tw21472.pp svneol=native#text/pascal
+tests/webtbs/tw21538.pp svneol=native#text/pascal
 tests/webtbs/tw21550.pp svneol=native#text/pascal
 tests/webtbs/tw21551.pp svneol=native#text/plain
 tests/webtbs/tw2158.pp svneol=native#text/plain
@@ -13666,6 +13667,7 @@ tests/webtbs/uw2040.pp svneol=native#text/plain
 tests/webtbs/uw20909a.pas svneol=native#text/pascal
 tests/webtbs/uw20909b.pas svneol=native#text/pascal
 tests/webtbs/uw20940.pp svneol=native#text/pascal
+tests/webtbs/uw21538.pp svneol=native#text/pascal
 tests/webtbs/uw21808a.pp svneol=native#text/plain
 tests/webtbs/uw21808b.pp svneol=native#text/plain
 tests/webtbs/uw22160a2.pp svneol=native#text/pascal

+ 29 - 0
compiler/defcmp.pas

@@ -204,6 +204,8 @@ implementation
          hct : tconverttype;
          hobjdef : tobjectdef;
          hpd : tprocdef;
+         i : longint;
+         diff : boolean;
       begin
          eq:=te_incompatible;
          doconv:=tc_not_possible;
@@ -262,6 +264,33 @@ implementation
               end;
            end;
 
+         { two specializations are considered equal if they specialize the same
+           generic with the same types }
+         if (df_specialization in def_from.defoptions) and
+             (df_specialization in def_to.defoptions) and
+             (tstoreddef(def_from).genericdef=tstoreddef(def_to).genericdef) then
+           begin
+             if tstoreddef(def_from).genericparas.count<>tstoreddef(def_to).genericparas.count then
+               internalerror(2012091301);
+             diff:=false;
+             for i:=0 to tstoreddef(def_from).genericparas.count-1 do
+               begin
+                 if tstoreddef(def_from).genericparas.nameofindex(i)<>tstoreddef(def_to).genericparas.nameofindex(i) then
+                   internalerror(2012091302);
+                 if tstoreddef(def_from).genericparas[i]<>tstoreddef(def_to).genericparas[i] then
+                   diff:=true;
+                 if diff then
+                   break;
+               end;
+             if not diff then
+               begin
+                 doconv:=tc_equal;
+                 { the definitions are not exactly the same, but only equal }
+                 compare_defs_ext:=te_equal;
+                 exit;
+               end;
+           end;
+
          { we walk the wanted (def_to) types and check then the def_from
            types if there is a conversion possible }
          case def_to.typ of

+ 19 - 0
tests/webtbs/tw21538.pp

@@ -0,0 +1,19 @@
+unit tw21538;
+
+{$IFDEF FPC}
+  {$MODE DELPHI}
+{$ENDIF}
+
+interface
+
+uses uw21538;
+
+var
+  ZZ: TWrapper<Integer>;
+
+implementation
+
+initialization
+  ZZ := Z;
+
+end.

+ 17 - 0
tests/webtbs/uw21538.pp

@@ -0,0 +1,17 @@
+unit uw21538;
+
+{$IFDEF FPC}
+  {$MODE DELPHI}
+{$ENDIF}
+
+interface
+
+type
+  TWrapper<T> = record end;
+
+var
+  Z: TWrapper<Integer>;
+
+implementation
+
+end.