Explorar o código

# revisions: 42328,42329

git-svn-id: branches/fixes_3_2@43401 -
marco %!s(int64=5) %!d(string=hai) anos
pai
achega
c4b9529d6b
Modificáronse 4 ficheiros con 48 adicións e 1 borrados
  1. 1 0
      .gitattributes
  2. 4 1
      compiler/pdecobj.pas
  3. 10 0
      compiler/pdecsub.pas
  4. 33 0
      tests/webtbs/tw35735.pp

+ 1 - 0
.gitattributes

@@ -16443,6 +16443,7 @@ tests/webtbs/tw3564.pp svneol=native#text/plain
 tests/webtbs/tw3567.pp svneol=native#text/plain
 tests/webtbs/tw3572.pp svneol=native#text/plain
 tests/webtbs/tw3573.pp svneol=native#text/plain
+tests/webtbs/tw35735.pp svneol=native#text/pascal
 tests/webtbs/tw3576.pp svneol=native#text/plain
 tests/webtbs/tw3577.pp svneol=native#text/plain
 tests/webtbs/tw3578.pp svneol=native#text/plain

+ 4 - 1
compiler/pdecobj.pas

@@ -1259,7 +1259,10 @@ implementation
                           begin
                             if (idtoken=_GENERIC) and
                                 not (m_delphi in current_settings.modeswitches) and
-                                not fields_allowed then
+                                (
+                                  not fields_allowed or
+                                  is_objectpascal_helper(current_structdef)
+                                ) then
                               begin
                                 if hadgeneric then
                                   Message(parser_e_procedure_or_function_expected);

+ 10 - 0
compiler/pdecsub.pas

@@ -1050,6 +1050,16 @@ implementation
                              HideSym(srsym);
                              searchagain:=true;
                            end
+                         else if (srsym.typ=typesym) and
+                             (sp_generic_dummy in srsym.symoptions) and
+                             (ttypesym(srsym).typedef.typ=undefineddef) then
+                           begin
+                             { this is a generic dummy symbol that has not yet
+                               been used; so we rename the dummy symbol and continue
+                               as if nothing happened }
+                             hidesym(srsym);
+                             searchagain:=true;
+                           end
                          else
                           begin
                             {  we use a different error message for tp7 so it looks more compatible }

+ 33 - 0
tests/webtbs/tw35735.pp

@@ -0,0 +1,33 @@
+{ %NORUN }
+
+program tw35735;
+
+{$Mode objfpc}
+
+uses
+  Classes, SysUtils;
+
+type
+
+  { TObjectHelper }
+
+  TObjectHelper = class helper for TObject
+  public
+    generic function Test<T>(): String;
+  end;
+
+{ TComponentHelper }
+
+generic function TObjectHelper.Test<T>: String;
+begin
+  Result := T.ClassName
+end;
+
+var
+  O: TObject;
+begin
+  O := TObject.Create;
+  WriteLn(O.specialize Test<TPersistent>);
+  O.Free;
+end.
+