diff --git a/.gitattributes b/.gitattributes
index f97d6dbb52..1ac0788714 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -8240,6 +8240,7 @@ tests/test/tforin19.pp svneol=native#text/pascal
 tests/test/tforin2.pp svneol=native#text/pascal
 tests/test/tforin20.pp svneol=native#text/pascal
 tests/test/tforin21.pp svneol=native#text/pascal
+tests/test/tforin22.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
diff --git a/compiler/nflw.pas b/compiler/nflw.pas
index dee54ac3c3..52bffce426 100644
--- a/compiler/nflw.pas
+++ b/compiler/nflw.pas
@@ -584,6 +584,8 @@ begin
       if movenext = nil then
       begin
         result:=cerrornode.create;
+        hloopvar.free;
+        hloopbody.free;
         Message1(sym_e_no_enumerator_move,pd.returndef.GetTypeName);
       end
       else
@@ -592,6 +594,8 @@ begin
         if current = nil then
         begin
           result:=cerrornode.create;
+          hloopvar.free;
+          hloopbody.free;
           Message1(sym_e_no_enumerator_current,pd.returndef.GetTypeName);
         end
         else
@@ -607,6 +611,8 @@ begin
       else
         begin
           result:=cerrornode.create;
+          hloopvar.free;
+          hloopbody.free;
           Message1(sym_e_no_enumerator,expr.resultdef.GetTypeName);
         end;
       end;
diff --git a/compiler/symdef.pas b/compiler/symdef.pas
index 94dc39d8a1..c692d3c4a0 100644
--- a/compiler/symdef.pas
+++ b/compiler/symdef.pas
@@ -4334,6 +4334,7 @@ implementation
                   pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
                   if (pd.proctypeoption = potype_function) and
                      is_boolean(pd.returndef) and
+                     (pd.minparacount = 0) and
                      (pd.visibility >= vis_public) then
                   begin
                     result:=pd;
diff --git a/tests/test/tforin22.pp b/tests/test/tforin22.pp
new file mode 100644
index 0000000000..1113b4254c
--- /dev/null
+++ b/tests/test/tforin22.pp
@@ -0,0 +1,27 @@
+{ %FAIL}
+{$mode objfpc}
+{$apptype console}
+
+type 
+  T = class
+    F: Integer;
+    function MoveNext(a: Integer): Boolean;
+    property Current: Integer read F;
+  end;
+
+function T.MoveNext(a: Integer): Boolean; 
+begin 
+  Result := true; 
+end;
+
+operator enumerator(a: Integer): T;
+begin
+  Result := T.Create;
+  Result.F := a;
+end;
+
+var
+  i: Integer;
+begin
+  for i in 1 do Writeln(i);
+end.