Browse Source

* create_for_in_loop: if there's a choice between iterating an array and a set then prefer the set for backwards compatibility

git-svn-id: trunk@36097 -
svenbarth 8 years ago
parent
commit
c6f19b9888
1 changed files with 9 additions and 0 deletions
  1. 9 0
      compiler/nflw.pas

+ 9 - 0
compiler/nflw.pas

@@ -925,6 +925,15 @@ implementation
                   end
                   end
                 else
                 else
                   begin
                   begin
+                    { prefer set if loop var could be a set var and the loop
+                      expression can indeed be a set }
+                    if (expr.nodetype=arrayconstructorn) and
+                        (hloopvar.resultdef.typ in [enumdef,orddef]) and
+                        arrayconstructor_can_be_set(expr) then
+                      begin
+                        expr:=arrayconstructor_to_set(expr,false);
+                        typecheckpass(expr);
+                      end;
                     case expr.resultdef.typ of
                     case expr.resultdef.typ of
                       stringdef: result:=create_string_for_in_loop(hloopvar, hloopbody, expr);
                       stringdef: result:=create_string_for_in_loop(hloopvar, hloopbody, expr);
                       arraydef: result:=create_array_for_in_loop(hloopvar, hloopbody, expr);
                       arraydef: result:=create_array_for_in_loop(hloopvar, hloopbody, expr);