Partial body resolve filter: fixed nested loops case
This commit is contained in:
@@ -268,7 +268,7 @@ class PartialBodyResolveFilter(
|
||||
private fun collectAlwaysExitPoints(statement: JetExpression?): Collection<JetExpression> {
|
||||
val result = ArrayList<JetExpression>()
|
||||
statement?.accept(object : ControlFlowVisitor() {
|
||||
var insideLoop = false
|
||||
var insideLoopLevel: Int = 0
|
||||
|
||||
override fun visitReturnExpression(expression: JetReturnExpression) {
|
||||
result.add(expression)
|
||||
@@ -303,9 +303,9 @@ class PartialBodyResolveFilter(
|
||||
override fun visitWhileExpression(loop: JetWhileExpression) {
|
||||
val condition = loop.getCondition()
|
||||
if (condition.isTrueConstant()) {
|
||||
insideLoop = true
|
||||
insideLoopLevel++
|
||||
loop.getBody()?.accept(this)
|
||||
insideLoop = false
|
||||
insideLoopLevel--
|
||||
}
|
||||
else {
|
||||
// do not make sense to search exits inside while-loop as not necessary enter it at all
|
||||
@@ -315,19 +315,19 @@ class PartialBodyResolveFilter(
|
||||
|
||||
override fun visitDoWhileExpression(loop: JetDoWhileExpression) {
|
||||
loop.getCondition()?.accept(this)
|
||||
insideLoop = true
|
||||
insideLoopLevel++
|
||||
loop.getBody()?.accept(this)
|
||||
insideLoop = false
|
||||
insideLoopLevel--
|
||||
}
|
||||
|
||||
override fun visitBreakExpression(expression: JetBreakExpression) {
|
||||
if (!insideLoop || expression.getLabelName() != null) {
|
||||
if (insideLoopLevel == 0 || expression.getLabelName() != null) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitContinueExpression(expression: JetContinueExpression) {
|
||||
if (!insideLoop || expression.getLabelName() != null) {
|
||||
if (insideLoopLevel == 0 || expression.getLabelName() != null) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
----------------------------------------------
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
// STATEMENT DELETED: if (x == null) { while (true) { do { println() } while(f()) break } }
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): Boolean{}
|
||||
@@ -0,0 +1,17 @@
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
if (x == null) {
|
||||
while (true) {
|
||||
do {
|
||||
println()
|
||||
} while(f())
|
||||
break
|
||||
}
|
||||
}
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): Boolean{}
|
||||
@@ -72,12 +72,6 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExpressionBody.kt")
|
||||
public void testExpressionBody() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/ExpressionBody.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExpressionBodyExplicitType.kt")
|
||||
public void testExpressionBodyExplicitType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/ExpressionBodyExplicitType.kt");
|
||||
@@ -306,6 +300,12 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("NestedLoop.kt")
|
||||
public void testNestedLoop() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/NestedLoop.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OutOfBodyResolve.kt")
|
||||
public void testOutOfBodyResolve() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/OutOfBodyResolve.kt");
|
||||
|
||||
Reference in New Issue
Block a user