Partial body resolve: don't be confused by exits after ?:
This commit is contained in:
@@ -274,6 +274,16 @@ class PartialBodyResolveFilter(elementToResolve: JetElement, private val body: J
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryExpression(expression: JetBinaryExpression) {
|
||||
if (expression.getOperationToken() == JetTokens.ELVIS) {
|
||||
// do not search exits after "?:"
|
||||
expression.getLeft()?.accept(this)
|
||||
}
|
||||
else {
|
||||
super.visitBinaryExpression(expression)
|
||||
}
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Resolve target: val x: kotlin.Any?
|
||||
Skipped statements:
|
||||
if (x == null) { print(1) val v = f() ?: return }
|
||||
@@ -0,0 +1,13 @@
|
||||
fun foo() {
|
||||
for (i in 1..10) {
|
||||
val x = take()
|
||||
if (x == null) {
|
||||
print(1)
|
||||
val v = f() ?: return
|
||||
}
|
||||
<caret>x.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
fun take(): Any? = null
|
||||
fun f(): String? = null
|
||||
@@ -19,6 +19,7 @@ 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;
|
||||
|
||||
@@ -149,6 +150,12 @@ public class PartialBodyResolveTestGenerated extends AbstractPartialBodyResolveT
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IfNullElvisReturn.kt")
|
||||
public void testIfNullElvisReturn() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/IfNullElvisReturn.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IfNullForWithReturn.kt")
|
||||
public void testIfNullForWithReturn() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/partialBodyResolve/IfNullForWithReturn.kt");
|
||||
|
||||
Reference in New Issue
Block a user