瀏覽代碼

* don't allow constants of the record type that is currently being parsed; this would fail as soon as another field is added after the constant declaration
+ added tests
Note: unlike what bug report 27880 suggests Delphi also does *NOT* allow this (at least a current Delphi Tokyo) and fails with a "type is not completely defined" error, so this test belongs into the "failure" category

git-svn-id: trunk@40285 -

svenbarth 6 年之前
父節點
當前提交
251dfb6776
共有 8 個文件被更改,包括 107 次插入2 次删除
  1. 6 1
      .gitattributes
  2. 3 0
      compiler/pdecl.pas
  3. 18 0
      tests/tbf/tb0261.pp
  4. 18 0
      tests/tbf/tb0262.pp
  5. 20 0
      tests/tbf/tb0263.pp
  6. 21 0
      tests/tbf/tb0264.pp
  7. 20 0
      tests/tbf/tb0265.pp
  8. 1 1
      tests/webtbf/tw27880.pp

+ 6 - 1
.gitattributes

@@ -11064,6 +11064,11 @@ tests/tbf/tb0257b.pp svneol=native#text/pascal
 tests/tbf/tb0258.pp svneol=native#text/pascal
 tests/tbf/tb0258.pp svneol=native#text/pascal
 tests/tbf/tb0259.pp svneol=native#text/plain
 tests/tbf/tb0259.pp svneol=native#text/plain
 tests/tbf/tb0260.pp svneol=native#text/plain
 tests/tbf/tb0260.pp svneol=native#text/plain
+tests/tbf/tb0261.pp svneol=native#text/pascal
+tests/tbf/tb0262.pp svneol=native#text/pascal
+tests/tbf/tb0263.pp svneol=native#text/pascal
+tests/tbf/tb0264.pp svneol=native#text/pascal
+tests/tbf/tb0265.pp svneol=native#text/pascal
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain
@@ -14657,6 +14662,7 @@ tests/webtbf/tw2739.pp svneol=native#text/plain
 tests/webtbf/tw2751.pp svneol=native#text/plain
 tests/webtbf/tw2751.pp svneol=native#text/plain
 tests/webtbf/tw2752.pp svneol=native#text/plain
 tests/webtbf/tw2752.pp svneol=native#text/plain
 tests/webtbf/tw2787.pp svneol=native#text/plain
 tests/webtbf/tw2787.pp svneol=native#text/plain
+tests/webtbf/tw27880.pp svneol=native#text/pascal
 tests/webtbf/tw2795.pp svneol=native#text/plain
 tests/webtbf/tw2795.pp svneol=native#text/plain
 tests/webtbf/tw28338.pp svneol=native#text/plain
 tests/webtbf/tw28338.pp svneol=native#text/plain
 tests/webtbf/tw28355.pp svneol=native#text/plain
 tests/webtbf/tw28355.pp svneol=native#text/plain
@@ -16031,7 +16037,6 @@ tests/webtbs/tw2780.pp svneol=native#text/plain
 tests/webtbs/tw27811.pp svneol=native#text/plain
 tests/webtbs/tw27811.pp svneol=native#text/plain
 tests/webtbs/tw27832.pp svneol=native#text/plain
 tests/webtbs/tw27832.pp svneol=native#text/plain
 tests/webtbs/tw2788.pp svneol=native#text/plain
 tests/webtbs/tw2788.pp svneol=native#text/plain
-tests/webtbs/tw27880.pp svneol=native#text/plain
 tests/webtbs/tw2789.pp svneol=native#text/plain
 tests/webtbs/tw2789.pp svneol=native#text/plain
 tests/webtbs/tw2794.pp svneol=native#text/plain
 tests/webtbs/tw2794.pp svneol=native#text/plain
 tests/webtbs/tw27998.pp svneol=native#text/plain
 tests/webtbs/tw27998.pp svneol=native#text/plain

+ 3 - 0
compiler/pdecl.pas

@@ -274,6 +274,9 @@ implementation
                      to it from the structure or linking will fail }
                      to it from the structure or linking will fail }
                    if symtablestack.top.symtabletype in [recordsymtable,ObjectSymtable] then
                    if symtablestack.top.symtabletype in [recordsymtable,ObjectSymtable] then
                      begin
                      begin
+                       { note: we keep hdef so that we might at least read the
+                               constant data correctly for error recovery }
+                       check_allowed_for_var_or_const(hdef,false);
                        sym:=cfieldvarsym.create(orgname,varspez,hdef,[],true);
                        sym:=cfieldvarsym.create(orgname,varspez,hdef,[],true);
                        symtablestack.top.insert(sym);
                        symtablestack.top.insert(sym);
                        sym:=make_field_static(symtablestack.top,tfieldvarsym(sym));
                        sym:=make_field_static(symtablestack.top,tfieldvarsym(sym));

+ 18 - 0
tests/tbf/tb0261.pp

@@ -0,0 +1,18 @@
+{ %FAIL }
+
+program tb0261;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+  public
+    a, b: LongInt;
+  public const
+    Test: TTest = (a: 42; b: 21);
+  end;
+
+begin
+
+end.

+ 18 - 0
tests/tbf/tb0262.pp

@@ -0,0 +1,18 @@
+{ %FAIL }
+
+program tb0262;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+  public
+    a, b: LongInt;
+  public const
+    Test: array[0..1] of TTest = ((a: 42; b: 21), (a: 21; b: 42));
+  end;
+
+begin
+
+end.

+ 20 - 0
tests/tbf/tb0263.pp

@@ -0,0 +1,20 @@
+{ %FAIL }
+
+program tb0263;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+  public
+    a, b: LongInt;
+  public const
+    Test: array[0..1] of record
+      t: TTest;
+    end = ((t: (a: 42; b: 21)), (t: (a: 21; b: 42)));
+  end;
+
+begin
+
+end.

+ 21 - 0
tests/tbf/tb0264.pp

@@ -0,0 +1,21 @@
+{ %FAIL }
+
+program tb0264;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+  public
+    a, b: LongInt;
+  public type
+    TSubType = record
+    public const
+      Test: TTest = (a: 42; b: 21);
+    end;
+  end;
+
+begin
+
+end.

+ 20 - 0
tests/tbf/tb0265.pp

@@ -0,0 +1,20 @@
+{ %FAIL }
+
+program tb0265;
+
+{$mode objfpc}
+{$modeswitch advancedrecords}
+
+type
+  TTest = record
+  public
+    a, b: LongInt;
+  public const
+    Test: array of record
+      t: TTest;
+    end = ((t: (a: 42; b: 21)), (t: (a: 21; b: 42)));
+  end;
+
+begin
+
+end.

+ 1 - 1
tests/webtbs/tw27880.pp → tests/webtbf/tw27880.pp

@@ -1,4 +1,4 @@
-{ %norun }
+{ %FAIL }
 
 
 program project1;
 program project1;