From ca8d45259b4f10cbf02902f072bd643b82fa40e2 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 18 Nov 2014 17:30:08 +0300 Subject: [PATCH] Partial body resolve: added a test to fail if smart-casts will become too clever --- .../lang/resolve/lazy/PartialBodyResolveFilter.kt | 1 - .../partialBodyResolve/WhileTrueCondition.dump | 3 +++ .../resolve/partialBodyResolve/WhileTrueCondition.kt | 12 ++++++++++++ .../jet/resolve/PartialBodyResolveTestGenerated.java | 7 ++++++- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 idea/testData/resolve/partialBodyResolve/WhileTrueCondition.dump create mode 100644 idea/testData/resolve/partialBodyResolve/WhileTrueCondition.kt diff --git a/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt b/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt index d1f45580dc3..2345b424bee 100644 --- a/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt +++ b/idea/ide-common/src/org/jetbrains/jet/lang/resolve/lazy/PartialBodyResolveFilter.kt @@ -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) } diff --git a/idea/testData/resolve/partialBodyResolve/WhileTrueCondition.dump b/idea/testData/resolve/partialBodyResolve/WhileTrueCondition.dump new file mode 100644 index 00000000000..f23bae1b0a4 --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/WhileTrueCondition.dump @@ -0,0 +1,3 @@ +Resolve target: value-parameter val p: kotlin.Any? +Skipped statements: +while(2 * 2 == 4) { print(p!!) if (x()) break } diff --git a/idea/testData/resolve/partialBodyResolve/WhileTrueCondition.kt b/idea/testData/resolve/partialBodyResolve/WhileTrueCondition.kt new file mode 100644 index 00000000000..d7168f1a899 --- /dev/null +++ b/idea/testData/resolve/partialBodyResolve/WhileTrueCondition.kt @@ -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 + } + + p.hashCode() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java b/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java index aa6b6579153..4d2e32017fe 100644 --- a/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/resolve/PartialBodyResolveTestGenerated.java @@ -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); + } }