Przeglądaj źródła

Fix for Mantis #27120.

pdecobj.pas, parse_object_members:
  * also allow class fields for helper types

+ added tests

git-svn-id: trunk@29270 -
svenbarth 10 lat temu
rodzic
commit
7b216d7fa6
4 zmienionych plików z 80 dodań i 1 usunięć
  1. 2 0
      .gitattributes
  2. 4 1
      compiler/pdecobj.pas
  3. 56 0
      tests/test/thlp47.pp
  4. 18 0
      tests/webtbs/tw27120.pp

+ 2 - 0
.gitattributes

@@ -11748,6 +11748,7 @@ tests/test/thlp43.pp svneol=native#text/pascal
 tests/test/thlp44.pp svneol=native#text/pascal
 tests/test/thlp45.pp svneol=native#text/pascal
 tests/test/thlp46.pp svneol=native#text/pascal
+tests/test/thlp47.pp svneol=native#text/pascal
 tests/test/thlp5.pp svneol=native#text/pascal
 tests/test/thlp6.pp svneol=native#text/pascal
 tests/test/thlp7.pp svneol=native#text/pascal
@@ -14164,6 +14165,7 @@ tests/webtbs/tw2706.pp svneol=native#text/plain
 tests/webtbs/tw2707.pp svneol=native#text/plain
 tests/webtbs/tw2708.pp svneol=native#text/plain
 tests/webtbs/tw2710.pp svneol=native#text/plain
+tests/webtbs/tw27120.pp svneol=native#text/pascal
 tests/webtbs/tw2713.pp svneol=native#text/plain
 tests/webtbs/tw2721.pp svneol=native#text/plain
 tests/webtbs/tw2723.pp svneol=native#text/plain

+ 4 - 1
compiler/pdecobj.pas

@@ -1216,7 +1216,10 @@ implementation
                           begin
                             if is_interface(current_structdef) or
                                is_objc_protocol_or_category(current_structdef) or
-                               is_objectpascal_helper(current_structdef) or
+                               (
+                                 is_objectpascal_helper(current_structdef) and
+                                 not class_fields
+                               ) or
                                (is_javainterface(current_structdef) and
                                 not(class_fields and final_fields)) then
                               Message(parser_e_no_vars_in_interfaces);

+ 56 - 0
tests/test/thlp47.pp

@@ -0,0 +1,56 @@
+{ This tests that class variables for the various helper kinds work correctly }
+
+program thlp47;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+{$modeswitch typehelpers}
+
+type
+  TObjectHelper = class helper for TObject
+  public
+    class procedure Init;
+  public class var
+    Value: LongInt;
+  end;
+
+  TGuidHelper = record helper for TGuid
+  public
+    class procedure Init; static;
+  public class var
+    Value: LongInt;
+  end;
+
+  TLongIntHelper = type helper for LongInt
+  public
+    class procedure Init; static;
+  public class var
+    Value: LongInt;
+  end;
+
+class procedure TObjectHelper.Init;
+begin
+  Value := 42;
+end;
+
+class procedure TGuidHelper.Init;
+begin
+  Value := 21;
+end;
+
+class procedure TLongIntHelper.Init;
+begin
+  Value := 84;
+end;
+
+begin
+  TObject.Init;
+  if TObject.Value <> 42 then
+    Halt(1);
+  TGuid.Init;
+  if TGuid.Value <> 21 then
+    Halt(2);
+  LongInt.Init;
+  if LongInt.Value <> 84 then
+    Halt(3);
+end.

+ 18 - 0
tests/webtbs/tw27120.pp

@@ -0,0 +1,18 @@
+{ %NORUN }
+
+program tw27120;
+
+{$mode objfpc}
+
+type
+  TFoo = class
+  end;
+
+  TBar = class helper for TFoo
+  private class var
+    FFoo: TFoo;
+  end;
+
+begin
+
+end.