compiler:

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

git-svn-id: trunk@14042 -
This commit is contained in:
paul 2009-11-04 12:25:01 +00:00
parent 5752be310d
commit 61ec5e1417
4 changed files with 24 additions and 0 deletions

2
.gitattributes vendored
View File

@ -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

View File

@ -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
tests/test/tforin18.pp Normal file
View File

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

7
tests/test/tforin19.pp Normal file
View File

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