Browse Source

* fix #41504: don't create synthetic methods for an objectdef that's a unique alias as that will use the original VMT and thus lead to duplicate assembly labels
+ added test

Sven/Sarah Barth 6 days ago
parent
commit
0ebe023534
3 changed files with 42 additions and 1 deletions
  1. 5 1
      compiler/symcreat.pas
  2. 21 0
      tests/webtbs/tw41504a.pp
  3. 16 0
      tests/webtbs/tw41504b.pp

+ 5 - 1
compiler/symcreat.pas

@@ -1884,7 +1884,11 @@ implementation
              (tprocdef(def).localst.symtabletype=localsymtable) then
             add_synthetic_method_implementations(tprocdef(def).localst)
           else if ((def.typ=objectdef) and
-                   not(oo_is_external in tobjectdef(def).objectoptions)) or
+                   not(oo_is_external in tobjectdef(def).objectoptions) and
+                   { we must not create duplicate synthetic methods for a unique
+                     type declaration as that simply shares the VMT of the aliased
+                     types }
+                   not(tobjectdef(def).is_unique_objpasdef)) or
                   (def.typ=recorddef) then
            begin
             { also complete nested types }

+ 21 - 0
tests/webtbs/tw41504a.pp

@@ -0,0 +1,21 @@
+{ %NORUN }
+
+program tw41504a;
+{$mode objFPC}
+
+type
+  TClassMain = class
+    procedure method; virtual; abstract;
+  end;
+
+  generic TGenClass<T> = class
+  type
+    TType = T;
+    TSelf = TGenClass;
+  end;
+
+  LType = type specialize TGenClass<TClassMain>.TSelf.TType;
+
+begin
+end.
+

+ 16 - 0
tests/webtbs/tw41504b.pp

@@ -0,0 +1,16 @@
+{ %NORUN }
+
+program tw41504b;
+
+{$mode objfpc}
+
+type
+  TTest = class
+    procedure Test; virtual; abstract;
+  end;
+
+  TTest2 = type TTest;
+
+begin
+
+end.