KT-13833 javascript: Smart type completion to lower priority of dynamic type

#KT-13833 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-09-27 19:15:42 +03:00
parent dbbba45d63
commit e8f4c65455
3 changed files with 26 additions and 3 deletions
@@ -34,12 +34,13 @@ import org.jetbrains.kotlin.idea.core.*
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.util.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.PossiblyBareType
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
import org.jetbrains.kotlin.types.isDynamic
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
import org.jetbrains.kotlin.types.typeUtil.isNothing
import org.jetbrains.kotlin.types.typeUtil.isNullableNothing
import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import java.util.*
@@ -300,8 +301,14 @@ fun DeclarationDescriptor.fuzzyTypesForSmartCompletion(
if (this is CallableDescriptor) {
val returnType = fuzzyReturnType() ?: return emptyList()
// skip declarations of type Nothing or of generic parameter type which has no real bounds
if (returnType.type.isNothing() || returnType.isAlmostEverything()) return emptyList()
// skip declarations of types Nothing, Nothing?, dynamic or of generic parameter type which has no real bounds
if (returnType.type.isNothing() ||
returnType.type.isNullableNothing() ||
returnType.type.isDynamic() ||
returnType.isAlmostEverything()) {
return emptyList()
}
if (this is VariableDescriptor) { //TODO: generic properties!
return smartCastCalculator.types(this).map { it.toFuzzyType(emptyList()) }
@@ -0,0 +1,10 @@
fun returnDynamic(): dynamic = TODO()
fun returnString(): String = ""
fun returnNothing(): Nothing? = TODO()
val test: Any? = return<caret>
// WITH_ORDER
// EXIST: returnString
// EXIST: returnDynamic
// EXIST: returnNothing
@@ -2683,6 +2683,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("DoNotPreferDynamic.kt")
public void testDoNotPreferDynamic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/js/DoNotPreferDynamic.kt");
doTest(fileName);
}
@TestMetadata("DynamicKeyword.kt")
public void testDynamicKeyword() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/js/DynamicKeyword.kt");