compiler: allow constructors in helpers for records

git-svn-id: trunk@23407 -
This commit is contained in:
paul 2013-01-16 13:47:22 +00:00
parent cce67cf5ae
commit e9615716c1
4 changed files with 35 additions and 6 deletions

1
.gitattributes vendored
View File

@ -11436,6 +11436,7 @@ tests/test/trhlp41.pp svneol=native#text/pascal
tests/test/trhlp42.pp svneol=native#text/pascal
tests/test/trhlp43.pp svneol=native#text/pascal
tests/test/trhlp44.pp svneol=native#text/pascal
tests/test/trhlp45.pp svneol=native#text/pascal
tests/test/trhlp5.pp svneol=native#text/pascal
tests/test/trhlp6.pp svneol=native#text/pascal
tests/test/trhlp7.pp svneol=native#text/pascal

View File

@ -901,11 +901,7 @@ implementation
if is_objectpascal_helper(astruct) then
if is_classdef then
{ class constructors are not allowed in class helpers }
Message(parser_e_no_class_constructor_in_helpers)
else if is_record(tobjectdef(astruct).extendeddef) then
{ as long as constructors aren't allowed in records they
aren't allowed in helpers either }
Message(parser_e_no_constructor_in_records);
Message(parser_e_no_class_constructor_in_helpers);
{ only 1 class constructor is allowed }
if is_classdef and (oo_has_class_constructor in astruct.objectoptions) then

View File

@ -493,7 +493,11 @@ implementation
end;
end
else
if not is_record(current_structdef) then
if not is_record(current_structdef) and
not (
is_objectpascal_helper(current_structdef) and
is_record(tobjectdef(current_structdef).extendeddef)
) then
internalerror(200305103);
{ if self=nil then exit
calling fail instead of exit is useless because

28
tests/test/trhlp45.pp Normal file
View File

@ -0,0 +1,28 @@
program trhlp45;
{$mode delphi}
type
TRec = record
X: Integer;
end;
THelpRec = record helper for TRec
constructor Create(AX: Integer);
end;
{ THelpRec }
constructor THelpRec.Create(AX: Integer);
begin
X := AX;
end;
var
R: TRec;
begin
R := TRec.Create(1);
if R.X <> 1 then
halt(1);
end.