From 7dfaec7a056ee0bc7332d7f9a9eb121b12982b4d Mon Sep 17 00:00:00 2001 From: svenbarth Date: Tue, 12 Jun 2012 09:42:22 +0000 Subject: [PATCH] Fix for Mantis #21457 * pdecsub.pas, parse_proc_dec & pdecobj.pas, constructor_head: correctly set the return type of the constructor of a class helper to the extended def * psub.pas, generate_bodyentry_block: call the NEWINSTANCE of the extended class for constructors of class helpers git-svn-id: trunk@21582 - --- .gitattributes | 1 + compiler/pdecobj.pas | 10 +++++++--- compiler/pdecsub.pas | 7 +++++-- compiler/psub.pas | 13 +++++++++++-- tests/webtbs/tw21457.pp | 24 ++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 tests/webtbs/tw21457.pp diff --git a/.gitattributes b/.gitattributes index c52f8871c0..2a76cc494b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12601,6 +12601,7 @@ tests/webtbs/tw2129b.pp svneol=native#text/plain tests/webtbs/tw2131.pp svneol=native#text/plain tests/webtbs/tw21443.pp svneol=native#text/plain tests/webtbs/tw2145.pp svneol=native#text/plain +tests/webtbs/tw21457.pp svneol=native#text/pascal tests/webtbs/tw21472.pp svneol=native#text/pascal tests/webtbs/tw21550.pp svneol=native#text/pascal tests/webtbs/tw21551.pp svneol=native#text/plain diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 535f810c9a..2b59d5aace 100644 --- a/compiler/pdecobj.pas +++ b/compiler/pdecobj.pas @@ -133,16 +133,20 @@ implementation consume(_SEMICOLON); include(current_structdef.objectoptions,oo_has_constructor); { Set return type, class and record constructors return the - created instance, object constructors return boolean } + created instance, helper types return the extended type, + object constructors return boolean } if is_class(pd.struct) or is_record(pd.struct) or is_javaclass(pd.struct) then pd.returndef:=pd.struct else + if is_objectpascal_helper(pd.struct) then + pd.returndef:=tobjectdef(pd.struct).extendeddef + else {$ifdef CPU64bitaddr} - pd.returndef:=bool64type; + pd.returndef:=bool64type; {$else CPU64bitaddr} - pd.returndef:=bool32type; + pd.returndef:=bool32type; {$endif CPU64bitaddr} constr_destr_finish_head(pd,pd.struct); result:=pd; diff --git a/compiler/pdecsub.pas b/compiler/pdecsub.pas index cc541b16b6..2fffdba62d 100644 --- a/compiler/pdecsub.pas +++ b/compiler/pdecsub.pas @@ -1107,10 +1107,13 @@ implementation is_javaclass(pd.struct) then pd.returndef:=pd.struct else + if is_objectpascal_helper(pd.struct) then + pd.returndef:=tobjectdef(pd.struct).extendeddef + else {$ifdef CPU64bitaddr} - pd.returndef:=bool64type; + pd.returndef:=bool64type; {$else CPU64bitaddr} - pd.returndef:=bool32type; + pd.returndef:=bool32type; {$endif CPU64bitaddr} end else diff --git a/compiler/psub.pas b/compiler/psub.pas index c614c041f5..673f4e7066 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -404,6 +404,7 @@ implementation para : tcallparanode; call : tcallnode; newstatement : tstatementnode; + def : tabstractrecorddef; begin result:=internalstatements(newstatement); @@ -412,9 +413,17 @@ implementation { a constructor needs a help procedure } if (current_procinfo.procdef.proctypeoption=potype_constructor) then begin - if is_class(current_structdef) then + if is_class(current_structdef) or + ( + is_objectpascal_helper(current_structdef) and + is_class(tobjectdef(current_structdef).extendeddef) + ) then begin - srsym:=search_struct_member(current_structdef,'NEWINSTANCE'); + if is_objectpascal_helper(current_structdef) then + def:=tabstractrecorddef(tobjectdef(current_structdef).extendeddef) + else + def:=current_structdef; + srsym:=search_struct_member(def,'NEWINSTANCE'); if assigned(srsym) and (srsym.typ=procsym) then begin diff --git a/tests/webtbs/tw21457.pp b/tests/webtbs/tw21457.pp new file mode 100644 index 0000000000..efde6895ac --- /dev/null +++ b/tests/webtbs/tw21457.pp @@ -0,0 +1,24 @@ +unit tw21457; +{$mode objfpc} +interface +uses Classes; + +Type + TFileStreamHelper = class helper for TFileStream + public + constructor CreateRetry(const AFileName: string; Mode: Word; Rights: Cardinal); + end; + + +implementation + +{ TFileStreamHelper } + +constructor TFileStreamHelper.CreateRetry(const AFileName:string; Mode:Word; Rights: Cardinal); +begin + //TODO + //=> internal error 200305103 +end; + + +end.