Java to Kotlin converter: fixed bug with unnecessary "run { }" construct generated in loop body

This commit is contained in:
Valentin Kipyatkov
2014-06-23 14:37:05 +04:00
parent 0e9edb7487
commit c458993fed
4 changed files with 17 additions and 1 deletions
@@ -130,7 +130,7 @@ open class StatementVisitor(public val converter: Converter) : JavaElementVisito
val updateConverted = converter.convertStatement(update)
val whileBody = if (updateConverted.isEmpty) {
converter.convertStatement(body)
convertStatementOrBlock(body)
}
else if (body is PsiBlockStatement) {
val nameConflict = initialization is PsiDeclarationStatement && initialization.getDeclaredElements().any { loopVar ->
@@ -1177,6 +1177,11 @@ public class JavaToKotlinConverterTestGenerated extends AbstractJavaToKotlinConv
doTest("j2k/tests/testData/ast/for/forWithReturn.java");
}
@TestMetadata("infiniteFor.java")
public void testInfiniteFor() throws Exception {
doTest("j2k/tests/testData/ast/for/infiniteFor.java");
}
}
@TestMetadata("j2k/tests/testData/ast/foreachStatement")
@@ -0,0 +1,6 @@
//method
void foo() {
for(;;) {
if (!stop()) break;
}
}
@@ -0,0 +1,5 @@
fun foo() {
while (true) {
if (!stop()) break
}
}