Skip to content

Commit daf7444

Browse files
suppress loop flattening for FLWOR with while clause (fixes #2634) (#2637)
1 parent 8dfc02c commit daf7444

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

basex-core/src/main/java/org/basex/query/expr/gflwor/GFLWOR.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,12 @@ public Expr copy(final CompileContext cc, final IntObjectMap<Var> vm) {
10381038
}
10391039

10401040
/**
1041-
* Checks if this FLWOR expression has only 'for', 'let', 'where', and 'while' clauses.
1041+
* Checks if this FLWOR expression has only 'for', 'let', and 'where' clauses.
10421042
* @return result of check
10431043
*/
10441044
private boolean isFLW() {
10451045
return ((Checks<Clause>) clause -> clause instanceof For || clause instanceof Let ||
1046-
clause instanceof Where || clause instanceof While).all(clauses);
1046+
clause instanceof Where).all(clauses);
10471047
}
10481048

10491049
@Override

basex-core/src/test/java/org/basex/query/expr/GFLWORTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,14 @@ public final class GFLWORTest extends SandboxTest {
523523
"1\n2", exists(Pipeline.class));
524524
check("let $a := <a/>[text()] while $a return $a", "", root(IterFilter.class));
525525
}
526+
527+
/** Do not flatten nested FLWOR expressions with while clauses. */
528+
@Test public void gh2634() {
529+
query("for $max in (1 to 10) return (for $a in 0 to $max while $a < 1 return $a)",
530+
"0\n0\n0\n0\n0\n0\n0\n0\n0\n0");
531+
query("for $x in (1, 2) return (for $a in (1, 2, 3) while $a < 3 return $a)",
532+
"1\n2\n1\n2");
533+
query("for $x in (1, 2) for $y in (for $a in (1, 2, 3) while $a < 3 return $a) return ($x, $y)",
534+
"1\n1\n1\n2\n2\n1\n2\n2");
535+
}
526536
}

0 commit comments

Comments
 (0)