Partial body resolve: added a test to fail if smart-casts will become too clever

This commit is contained in:
Valentin Kipyatkov
2014-11-18 17:30:08 +03:00
parent e7ba59b209
commit ca8d45259b
4 changed files with 21 additions and 2 deletions
@@ -175,7 +175,6 @@ class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: J
override fun visitWhileExpression(expression: JetWhileExpression) {
val condition = expression.getCondition()
// we need to enter the body only for "while(true)"
//TODO: what about e.g. "1 == 1"
if (condition.isTrueConstant()) {
expression.acceptChildren(this)
}
@@ -0,0 +1,3 @@
Resolve target: value-parameter val p: kotlin.Any?
Skipped statements:
while(2 * 2 == 4) { print(p!!) if (x()) break }
@@ -0,0 +1,12 @@
// this test will fail if control flow analysis will start to produce smart-casts after "while(2 * 2 == 4)"
fun x(): Boolean{}
fun foo(p: Any?) {
while(2 * 2 == 4) {
print(p!!)
if (x()) break
}
<caret>p.hashCode()
}
@@ -19,7 +19,6 @@ package org.jetbrains.jet.resolve;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.junit.runner.RunWith;
@@ -227,4 +226,10 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/WhileTrue.kt");
doTest(fileName);
}
@TestMetadata("WhileTrueCondition.kt")
public void testWhileTrueCondition() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/WhileTrueCondition.kt");
doTest(fileName);
}
}