From c4b9529d6bdc3246d6990fe81663eeddc12ad838 Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 5 Nov 2019 16:22:23 +0000 Subject: [PATCH] # revisions: 42328,42329 git-svn-id: branches/fixes_3_2@43401 - --- .gitattributes | 1 + compiler/pdecobj.pas | 5 ++++- compiler/pdecsub.pas | 10 ++++++++++ tests/webtbs/tw35735.pp | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw35735.pp diff --git a/.gitattributes b/.gitattributes index a338ecac25..355d5f152a 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 1496257e74..cfb999f82c 100644 --- a/compiler/pdecobj.pas +++ b/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); diff --git a/compiler/pdecsub.pas b/compiler/pdecsub.pas index e81b06b8e5..61c4d91005 100644 --- a/compiler/pdecsub.pas +++ b/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 } diff --git a/tests/webtbs/tw35735.pp b/tests/webtbs/tw35735.pp new file mode 100644 index 0000000000..9116d99a82 --- /dev/null +++ b/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(): String; + end; + +{ TComponentHelper } + +generic function TObjectHelper.Test: String; +begin + Result := T.ClassName +end; + +var + O: TObject; +begin + O := TObject.Create; + WriteLn(O.specialize Test); + O.Free; +end. +