Skip to content

Commit ed32cd2

Browse files
committed
Be more lenient on allowed loops
This also fixes a potential issue where `repeat` would be generated despite counting down
1 parent 9ebff04 commit ed32cd2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

plugins/kotlin/src/main/java/org/vineflower/kotlin/stat/KDoStatement.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public TextBuffer toJava(int indent) {
121121
getInitExprent() instanceof AssignmentExprent init &&
122122
init.getLeft() instanceof VarExprent varExpr &&
123123
isIntegerType(varExpr.getExprType()) &&
124-
init.getRight() instanceof ConstExprent constExpr &&
124+
// init.getRight() instanceof ConstExprent constExpr &&
125125

126126
getIncExprent() instanceof FunctionExprent inc &&
127127
inc.getFuncType().isPPMM() &&
@@ -158,9 +158,17 @@ public TextBuffer toJava(int indent) {
158158
}
159159
}
160160

161-
constExpr.setConstType(varExpr.getExprType());
161+
// constExpr.setConstType(varExpr.getExprType());
162+
if (init.getRight() instanceof ConstExprent constExpr) {
163+
constExpr.setConstType(varExpr.getExprType());
164+
}
162165

163-
if (constExpr.getValue() instanceof Integer i && i == 0) {
166+
if (
167+
inc.getFuncType().isPP() &&
168+
init.getRight() instanceof ConstExprent constExpr &&
169+
constExpr.getValue() instanceof Integer i
170+
&& i == 0
171+
) {
164172
buf.append("repeat(")
165173
.append(conditionExpr.toJava())
166174
.append(") ");
@@ -189,7 +197,7 @@ public TextBuffer toJava(int indent) {
189197
buf.append("for (")
190198
.append(varExpr.toJava(indent))
191199
.append(" in ")
192-
.append(constExpr.toJava())
200+
.append(init.getRight().toJava())
193201
.append(inc.getFuncType().isPP() ? ".." : " downTo ")
194202
.append(conditionExpr.toJava())
195203
.append(") {")

0 commit comments

Comments
 (0)