Browse Source

* Fix #40716: only add helpers if the type doesn't belong to the current object/class/record hierarchy
+ added test

Sven/Sarah Barth 1 year ago
parent
commit
e76c5d96d8
2 changed files with 28 additions and 1 deletions
  1. 2 1
      compiler/symdef.pas
  2. 26 0
      tests/webtbs/tw40716.pp

+ 2 - 1
compiler/symdef.pas

@@ -1845,7 +1845,8 @@ implementation
                 { add nested helpers as well }
                 if assigned(def) and
                     (def.typ in [recorddef,objectdef]) and
-                    (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) then
+                    (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) and
+                    not is_owned_by(def,tdef(st.defowner)) then
                   add_helpers_and_generics(tabstractrecorddef(def).symtable,false);
               end;
           end;

+ 26 - 0
tests/webtbs/tw40716.pp

@@ -0,0 +1,26 @@
+{ %NORUN }
+
+program tw40716;
+{$mode objfpc}{$H+}
+{uses
+  gmap,gutil;}
+type
+  generic GMyMap<TKey, TValue, TCompare>=class//(specialize TMap<TKey, TValue, TCompare>)
+    type
+      TSelf=specialize GMyMap<TKey, TValue, TCompare>;
+      TMyMapHelper = class helper for TSelf
+        function test:integer;
+      end;
+    procedure Foo;
+  end;
+function GMyMap.TMyMapHelper.test:integer;
+begin
+  result:=42;//FSet.Size;
+end;
+procedure GMyMap.Foo;
+begin
+  Self.Test;
+end;
+begin
+end.
+