Explorar el Código

* only allow using array elements as for-loop counter variables
in TP mode

git-svn-id: trunk@8907 -

Jonas Maebe hace 18 años
padre
commit
12b4f034ea
Se han modificado 5 ficheros con 40 adiciones y 9 borrados
  1. 2 0
      .gitattributes
  2. 13 9
      compiler/pstatmnt.pas
  3. 11 0
      tests/webtbf/tw9072a.pp
  4. 12 0
      tests/webtbf/tw9072b.pp
  5. 2 0
      tests/webtbs/tw1407.pp

+ 2 - 0
.gitattributes

@@ -7487,6 +7487,8 @@ tests/webtbf/tw9039b.pp svneol=native#text/plain
 tests/webtbf/tw9039c.pp svneol=native#text/plain
 tests/webtbf/tw9039d.pp svneol=native#text/plain
 tests/webtbf/tw9053.pp svneol=native#text/plain
+tests/webtbf/tw9072a.pp svneol=native#text/plain
+tests/webtbf/tw9072b.pp svneol=native#text/plain
 tests/webtbf/tw9225.pp svneol=native#text/plain
 tests/webtbf/tw9306c.pp svneol=native#text/plain
 tests/webtbf/tw9499.pp svneol=native#text/plain

+ 13 - 9
compiler/pstatmnt.pas

@@ -325,17 +325,21 @@ implementation
          hp:=hloopvar;
          while assigned(hp) and
                (
-                { record/object fields are allowed in tp7 mode only }
+                { record/object fields and array elements are allowed }
+                { in tp7 mode only                                    }
                 (
                  (m_tp7 in current_settings.modeswitches) and
-                 (hp.nodetype=subscriptn) and
-                 ((tsubscriptnode(hp).left.resultdef.typ=recorddef) or
-                  is_object(tsubscriptnode(hp).left.resultdef))
-                ) or
-                { constant array index }
-                (
-                 (hp.nodetype=vecn) and
-                 is_constintnode(tvecnode(hp).right)
+                 (
+                  ((hp.nodetype=subscriptn) and
+                   ((tsubscriptnode(hp).left.resultdef.typ=recorddef) or
+                    is_object(tsubscriptnode(hp).left.resultdef))
+                  ) or
+                  { constant array index }
+                  (
+                   (hp.nodetype=vecn) and
+                   is_constintnode(tvecnode(hp).right)
+                  )
+                 )
                 ) or
                 { equal typeconversions }
                 (

+ 11 - 0
tests/webtbf/tw9072a.pp

@@ -0,0 +1,11 @@
+{ %fail }
+
+{$mode tp}
+
+var
+  a: array[1..10] of byte;
+  b:  byte;
+begin
+  b:=1;
+  for a[b] := 1 to 10 do ;
+end.

+ 12 - 0
tests/webtbf/tw9072b.pp

@@ -0,0 +1,12 @@
+{ %fail }
+
+var
+  a: array[1..2] of longint;
+  l: longint;
+begin
+  l:=0;
+  for a[1]:=1 to 10 do
+    inc(l);
+  if (l<>10) then
+    halt(1);
+end.

+ 2 - 0
tests/webtbs/tw1407.pp

@@ -3,6 +3,8 @@
 { e-mail: [email protected] }
 { compiled with 1.04 on win32 }
 { options : -B -CX -XXs -OG2p3 -So }
+{$mode tp}
+
 var
         a : array[1..10] of integer;
         i : byte;