浏览代码

* handle for ... in on arrays of constant correctly, resolves also #25838
+ tests

git-svn-id: trunk@27039 -

florian 11 年之前
父节点
当前提交
08a4e1efe1
共有 4 个文件被更改,包括 57 次插入1 次删除
  1. 2 0
      .gitattributes
  2. 2 1
      compiler/nflw.pas
  3. 21 0
      tests/test/tforin26.pp
  4. 32 0
      tests/test/tforin27.pp

+ 2 - 0
.gitattributes

@@ -11348,6 +11348,8 @@ tests/test/tforin22.pp svneol=native#text/pascal
 tests/test/tforin23.pp svneol=native#text/pascal
 tests/test/tforin24.pp svneol=native#text/pascal
 tests/test/tforin25.pp svneol=native#text/pascal
+tests/test/tforin26.pp svneol=native#text/pascal
+tests/test/tforin27.pp svneol=native#text/pascal
 tests/test/tforin3.pp svneol=native#text/pascal
 tests/test/tforin4.pp svneol=native#text/pascal
 tests/test/tforin5.pp svneol=native#text/pascal

+ 2 - 1
compiler/nflw.pas

@@ -579,7 +579,8 @@ implementation
               end;
           end;
 
-        if (node_complexity(expression) > 1) and not is_open_array(expression.resultdef) then
+        if (node_complexity(expression) > 1) and
+          not(is_open_array(expression.resultdef)) and not(is_array_of_const(expression.resultdef)) then
           begin
             { create a temp variable for expression }
             arrayvar := ctempcreatenode.create(

+ 21 - 0
tests/test/tforin26.pp

@@ -0,0 +1,21 @@
+{$mode objfpc}
+Function Write(Const Args: Array of const) : Integer;
+
+Var
+  V : TVarRec;
+begin
+  result:=0;
+  For V in Args do
+    begin
+      if V.VType<>vtInteger then
+        halt(1);
+      inc(result);
+    end;
+end;
+
+begin
+  if Write([1,2,3,4])<>4 then
+    halt(1);
+  writeln('ok');
+end.
+

+ 32 - 0
tests/test/tforin27.pp

@@ -0,0 +1,32 @@
+{$mode objfpc}
+type
+  TIntegerDynArray = array of Integer;
+
+Function Write(Const Args: TIntegerDynArray) : Integer;
+
+function GetArgs : TIntegerDynArray;
+  begin
+    GetArgs:=Args;
+  end;
+
+Var
+  I : Integer;
+begin
+  result:=0;
+  For I in GetArgs do
+    begin
+      inc(result,i);
+      inc(result);
+    end;
+end;
+
+var
+  IntegerDynArray : TIntegerDynArray;
+
+begin
+  SetLength(IntegerDynArray,4);
+  if Write(IntegerDynArray)<>4 then
+    halt(1);
+  writeln('ok');
+end.
+