From 61ec5e1417281a7b1530daf999fcaf94cd9ef649 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 4 Nov 2009 12:25:01 +0000 Subject: [PATCH] compiler: - fix for-in loop for empty sets - add some test from Alexander S. Klenin (issue #0014990) git-svn-id: trunk@14042 - --- .gitattributes | 2 ++ compiler/nflw.pas | 9 +++++++++ tests/test/tforin18.pp | 6 ++++++ tests/test/tforin19.pp | 7 +++++++ 4 files changed, 24 insertions(+) create mode 100644 tests/test/tforin18.pp create mode 100644 tests/test/tforin19.pp diff --git a/.gitattributes b/.gitattributes index 896aafd913..5a21cad504 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/nflw.pas b/compiler/nflw.pas index 9a055bd7ff..dee54ac3c3 100644 --- a/compiler/nflw.pas +++ b/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); diff --git a/tests/test/tforin18.pp b/tests/test/tforin18.pp new file mode 100644 index 0000000000..d37bd7f3d5 --- /dev/null +++ b/tests/test/tforin18.pp @@ -0,0 +1,6 @@ +{ %FAIL} +{$mode objfpc} +{$apptype console} +begin + for ch in S do Writeln(ch); +end. diff --git a/tests/test/tforin19.pp b/tests/test/tforin19.pp new file mode 100644 index 0000000000..1119b561f3 --- /dev/null +++ b/tests/test/tforin19.pp @@ -0,0 +1,7 @@ +{$mode objfpc} +{$apptype console} +var + ch: Char; +begin + for ch in [] do Writeln(ch); +end.