Smart completion: don't use outer call's expected type too much

This commit is contained in:
Valentin Kipyatkov
2015-07-21 11:22:35 +03:00
parent a5384cdc28
commit 2ad981d5c9
8 changed files with 61 additions and 36 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.idea.util
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl
@@ -24,11 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.registerTypeVariables
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.types.typeUtil.nullability
import org.jetbrains.kotlin.types.typeUtil.*
import java.util.HashSet
fun CallableDescriptor.fuzzyReturnType(): FuzzyType? {
@@ -45,6 +42,13 @@ fun FuzzyType.makeNotNullable() = FuzzyType(type.makeNotNullable(), freeParamete
fun FuzzyType.makeNullable() = FuzzyType(type.makeNullable(), freeParameters)
fun FuzzyType.nullability() = type.nullability()
fun FuzzyType.isAlmostAnyType(): Boolean {
if (freeParameters.isEmpty()) return false
val typeParameter = type.constructor.declarationDescriptor as? TypeParameterDescriptor ?: return false
if (typeParameter !in freeParameters) return false
return typeParameter.upperBoundsAsType.isAnyOrNullableAny()
}
class FuzzyType(
val type: JetType,
freeParameters: Collection<TypeParameterDescriptor>