Constraint incorporation

In a constraint system a new bound is incorporated:
all new constrains that can be derived from it
(and from existing ones) are added
This commit is contained in:
Svetlana Isakova
2015-06-27 13:49:11 +03:00
parent 82acce4767
commit 9a5abf368f
30 changed files with 531 additions and 225 deletions
@@ -16,18 +16,15 @@
package org.jetbrains.kotlin.idea.util
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.utils.addIfNotNull
import java.util.HashSet
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl
import java.util.LinkedHashMap
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintsUtil
import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind
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 java.util.HashSet
fun CallableDescriptor.fuzzyReturnType(): FuzzyType? {
val returnType = getReturnType() ?: return null
@@ -103,18 +100,14 @@ class FuzzyType(
}
val constraintSystem = ConstraintSystemImpl()
val typeVariables = LinkedHashMap<TypeParameterDescriptor, Variance>()
for (typeParameter in freeParameters) {
typeVariables[typeParameter] = Variance.INVARIANT
}
constraintSystem.registerTypeVariables(typeVariables)
constraintSystem.registerTypeVariables(freeParameters, { Variance.INVARIANT })
when (matchKind) {
MatchKind.IS_SUBTYPE -> constraintSystem.addSubtypeConstraint(type, otherType, ConstraintPositionKind.SPECIAL.position())
MatchKind.IS_SUPERTYPE -> constraintSystem.addSubtypeConstraint(otherType, type, ConstraintPositionKind.SPECIAL.position())
}
constraintSystem.processDeclaredBoundConstraints()
constraintSystem.fixVariables()
if (!constraintSystem.getStatus().hasContradiction()) {
// currently ConstraintSystem return successful status in case there are problems with nullability