From 4c5d5ed18f1cdf994e106adfed3170e5958461b7 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 6 Nov 2015 15:25:59 +0300 Subject: [PATCH] Do not show "assertFailsWith" in any smart completion --- .../jetbrains/kotlin/idea/util/FuzzyType.kt | 24 ++++++++----------- .../testData/smart/NoAssertFailsWith.kt | 11 +++++++++ .../test/JvmSmartCompletionTestGenerated.java | 6 +++++ 3 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 idea/idea-completion/testData/smart/NoAssertFailsWith.kt diff --git a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt index 25938f7f186..135a39de1f5 100644 --- a/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt +++ b/idea/ide-common/src/org/jetbrains/kotlin/idea/util/FuzzyType.kt @@ -128,19 +128,15 @@ class FuzzyType( constraintSystem.fixVariables() - if (!constraintSystem.getStatus().hasContradiction()) { - // currently ConstraintSystem return successful status in case there are problems with nullability - // that's why we have to check subtyping manually - val substitutor = constraintSystem.getResultingSubstitutor() - val substitutedType = substitutor.substitute(type, Variance.INVARIANT) - val otherSubstitutedType = substitutor.substitute(otherType.type, Variance.INVARIANT) - return if (substitutedType != null && otherSubstitutedType != null && substitutedType.checkInheritance(otherSubstitutedType)) - constraintSystem.getPartialSubstitutor() - else - null - } - else { - return null - } + if (constraintSystem.getStatus().hasContradiction()) return null + + // currently ConstraintSystem return successful status in case there are problems with nullability + // that's why we have to check subtyping manually + val substitutor = constraintSystem.getResultingSubstitutor() + val substitutedType = substitutor.substitute(type, Variance.INVARIANT) ?: return null + if (substitutedType.isError) return null + val otherSubstitutedType = substitutor.substitute(otherType.type, Variance.INVARIANT) ?: return null + if (otherSubstitutedType.isError) return null + return if (substitutedType.checkInheritance(otherSubstitutedType)) constraintSystem.getPartialSubstitutor() else null } } diff --git a/idea/idea-completion/testData/smart/NoAssertFailsWith.kt b/idea/idea-completion/testData/smart/NoAssertFailsWith.kt new file mode 100644 index 00000000000..a758ca4b79a --- /dev/null +++ b/idea/idea-completion/testData/smart/NoAssertFailsWith.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +interface I + +fun foo(i: I){} + +fun bar() { + foo(ass) +} + +// ABSENT: assertFailsWith diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java index 05be2518e38..baec6954797 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/JvmSmartCompletionTestGenerated.java @@ -323,6 +323,12 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT doTest(fileName); } + @TestMetadata("NoAssertFailsWith.kt") + public void testNoAssertFailsWith() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/NoAssertFailsWith.kt"); + doTest(fileName); + } + @TestMetadata("NoExtensionMethodFromClassObject.kt") public void testNoExtensionMethodFromClassObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/smart/NoExtensionMethodFromClassObject.kt");