Support contracts in PartialBodyResolveFilter

Previously, PartialBodyResolveFilter didn't know about contracts and was
filtering out calls of such functions, leading to unstable completion in
cases like that:

fun test(x: Any?) {
    require(x is String)
    x.<caret>
}

However, PartialBodyResolveFilter works by pure PSI, while to determine
if function has a contract we have to resolve it.

To solve it, we do something very similar to what has been done with
Nothin-returning functions: introduce
KotlinProbablyContractedFunctionShortNameIndex, which collects all
function which *may* have a contract during indexing.

^KT-25275 Fixed
This commit is contained in:
Dmitry Savvinov
2018-07-20 19:35:45 +03:00
parent 5ab79a111d
commit f90b29c2e3
23 changed files with 293 additions and 2 deletions
@@ -0,0 +1,15 @@
// COMPILER_ARGUMENTS: -XXLanguage:+ReadDeserializedContracts -XXLanguage:+UseReturnsEffect
interface Foo {
val x: Int
fun f()
}
fun test(x: Any?) {
require(x is Foo)
x.<caret>
}
// EXIST: x
// EXIST: f
@@ -2218,6 +2218,11 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common/smartCast"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("functionWithContract.kt")
public void testFunctionWithContract() throws Exception {
runTest("idea/idea-completion/testData/basic/common/smartCast/functionWithContract.kt");
}
@TestMetadata("MemberExtensionAfterThisSmartCast.kt")
public void testMemberExtensionAfterThisSmartCast() throws Exception {
runTest("idea/idea-completion/testData/basic/common/smartCast/MemberExtensionAfterThisSmartCast.kt");
@@ -2218,6 +2218,11 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/common/smartCast"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("functionWithContract.kt")
public void testFunctionWithContract() throws Exception {
runTest("idea/idea-completion/testData/basic/common/smartCast/functionWithContract.kt");
}
@TestMetadata("MemberExtensionAfterThisSmartCast.kt")
public void testMemberExtensionAfterThisSmartCast() throws Exception {
runTest("idea/idea-completion/testData/basic/common/smartCast/MemberExtensionAfterThisSmartCast.kt");