Pārlūkot izejas kodu

compiler: allow constructors in helpers for records

git-svn-id: trunk@23407 -
paul 12 gadi atpakaļ
vecāks
revīzija
e9615716c1
4 mainītis faili ar 35 papildinājumiem un 6 dzēšanām
  1. 1 0
      .gitattributes
  2. 1 5
      compiler/pdecobj.pas
  3. 5 1
      compiler/psub.pas
  4. 28 0
      tests/test/trhlp45.pp

+ 1 - 0
.gitattributes

@@ -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

+ 1 - 5
compiler/pdecobj.pas

@@ -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

+ 5 - 1
compiler/psub.pas

@@ -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 - 0
tests/test/trhlp45.pp

@@ -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.