Browse Source

compiler:
- fix for-in loop for empty sets
- add some test from Alexander S. Klenin
(issue #0014990)

git-svn-id: trunk@14042 -

paul 16 years ago
parent
commit
61ec5e1417
4 changed files with 24 additions and 0 deletions
  1. 2 0
      .gitattributes
  2. 9 0
      compiler/nflw.pas
  3. 6 0
      tests/test/tforin18.pp
  4. 7 0
      tests/test/tforin19.pp

+ 2 - 0
.gitattributes

@@ -8235,6 +8235,8 @@ tests/test/tforin14.pp svneol=native#text/pascal
 tests/test/tforin15.pp svneol=native#text/pascal
 tests/test/tforin16.pp svneol=native#text/pascal
 tests/test/tforin17.pp svneol=native#text/pascal
+tests/test/tforin18.pp svneol=native#text/pascal
+tests/test/tforin19.pp svneol=native#text/pascal
 tests/test/tforin2.pp svneol=native#text/pascal
 tests/test/tforin3.pp svneol=native#text/pascal
 tests/test/tforin4.pp svneol=native#text/pascal

+ 9 - 0
compiler/nflw.pas

@@ -390,6 +390,15 @@ var
   loopvar, setvar: ttempcreatenode;
   loopbody, forloopnode: tnode;
 begin
+  // first check is set is empty and if it so then skip other processing
+  if not Assigned(tsetdef(expr.resultdef).elementdef) then
+  begin
+    result:=cnothingnode.create;
+    // free unused nodes
+    hloopvar.free;
+    hloopbody.free;
+    exit;
+  end;
   { result is a block of statements }
   result:=internalstatements(loopstatement);
 

+ 6 - 0
tests/test/tforin18.pp

@@ -0,0 +1,6 @@
+{ %FAIL}
+{$mode objfpc}
+{$apptype console}
+begin
+  for ch in S do Writeln(ch);
+end.

+ 7 - 0
tests/test/tforin19.pp

@@ -0,0 +1,7 @@
+{$mode objfpc}
+{$apptype console}
+var
+  ch: Char;
+begin
+  for ch in [] do Writeln(ch);
+end.