Browse Source

tcallcandidates.collect_overloads_in_struct: When the available methods are searched inside a helper then we need to look for methods in the extended types as well if an "overload" was given.

git-svn-id: branches/svenbarth/classhelpers@17837 -
svenbarth 14 years ago
parent
commit
f3c74a8297
3 changed files with 56 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 16 0
      compiler/htypechk.pas
  3. 39 0
      tests/test/thlp45.pp

+ 1 - 0
.gitattributes

@@ -10059,6 +10059,7 @@ tests/test/thlp41.pp svneol=native#text/pascal
 tests/test/thlp42.pp svneol=native#text/pascal
 tests/test/thlp42.pp svneol=native#text/pascal
 tests/test/thlp43.pp svneol=native#text/pascal
 tests/test/thlp43.pp svneol=native#text/pascal
 tests/test/thlp44.pp svneol=native#text/pascal
 tests/test/thlp44.pp svneol=native#text/pascal
+tests/test/thlp45.pp svneol=native#text/pascal
 tests/test/thlp5.pp svneol=native#text/pascal
 tests/test/thlp5.pp svneol=native#text/pascal
 tests/test/thlp6.pp svneol=native#text/pascal
 tests/test/thlp6.pp svneol=native#text/pascal
 tests/test/thlp7.pp svneol=native#text/pascal
 tests/test/thlp7.pp svneol=native#text/pascal

+ 16 - 0
compiler/htypechk.pas

@@ -1865,6 +1865,22 @@ implementation
                if not hasoverload then
                if not hasoverload then
                  break;
                  break;
              end;
              end;
+           if is_objectpascal_helper(structdef) then
+             begin
+               if not assigned(tobjectdef(structdef).extendeddef) then
+                 Internalerror(2011062601);
+               { search methods in the extended type as well }
+               srsym:=tprocsym(tobjectdef(structdef).extendeddef.symtable.FindWithHash(hashedid));
+               if assigned(srsym) and
+                  { Delphi allows hiding a property by a procedure with the same name }
+                  (srsym.typ=procsym) then
+                 begin
+                   hasoverload:=processprocsym(tprocsym(srsym));
+                   { when there is no explicit overload we stop searching }
+                   if not hasoverload then
+                     break;
+                 end;
+             end;
            { next parent }
            { next parent }
            if (structdef.typ=objectdef) then
            if (structdef.typ=objectdef) then
              structdef:=tobjectdef(structdef).childof
              structdef:=tobjectdef(structdef).childof

+ 39 - 0
tests/test/thlp45.pp

@@ -0,0 +1,39 @@
+{ this tests that the correct method is called if a helper overloads an
+  existing function and calls the original one recursively }
+program thlp45;
+
+{$mode objfpc}{$H+}
+
+type
+  TTest = class
+    function Test(aRecurse: Boolean; aTest: String): Integer;
+  end;
+
+  TTestHelper = class helper for TTest
+    function Test(aRecurse: Boolean; aTest: array of String): Integer; overload;
+  end;
+
+function TTest.Test(aRecurse: Boolean; aTest: String): Integer;
+begin
+  Result := 1;
+end;
+
+function TTestHelper.Test(aRecurse: Boolean; aTest: array of String): Integer;
+begin
+  if aRecurse then
+    Result := Test(False, aTest[0])
+  else
+    Result := 2;  
+end;
+
+var
+  t: TTest;
+  res: Integer;
+begin
+  t := TTest.Create;
+  res := t.Test(True, ['Test']);
+  Writeln('t.Test: ', res);
+  if res <> 1 then
+    Halt(1);
+  Writeln('ok');
+end.