Fixes after merge

Added platform types fixes to rewritten to kotlin files
This commit is contained in:
Svetlana Isakova
2014-12-01 21:20:13 +03:00
parent 26a54aa95d
commit 4df8c250ab
2 changed files with 31 additions and 9 deletions
@@ -42,6 +42,10 @@ import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.Constra
import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.ConstraintPositionKind.* import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.ConstraintPositionKind.*
import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.CompoundConstraintPosition import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.CompoundConstraintPosition
import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.getCompoundConstraintPosition import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.getCompoundConstraintPosition
import org.jetbrains.jet.lang.types.CustomTypeVariable
import org.jetbrains.jet.lang.types.getCustomTypeVariable
import org.jetbrains.jet.lang.types.isFlexible
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
public class ConstraintSystemImpl : ConstraintSystem { public class ConstraintSystemImpl : ConstraintSystem {
@@ -283,7 +287,7 @@ public class ConstraintSystemImpl : ConstraintSystem {
fun simplifyConstraint(subType: JetType, superType: JetType) { fun simplifyConstraint(subType: JetType, superType: JetType) {
// can be equal for the recursive invocations: // can be equal for the recursive invocations:
// fun <T> foo(i: Int) : T { ... return foo(i); } => T <: T // fun <T> foo(i: Int) : T { ... return foo(i); } => T <: T
if (subType == superType) return if (isMyTypeVariable(subType) && isMyTypeVariable(superType) && JetTypeChecker.DEFAULT.equalTypes(subType, superType)) return
assert(!isMyTypeVariable(subType) || !isMyTypeVariable(superType)) { assert(!isMyTypeVariable(subType) || !isMyTypeVariable(superType)) {
"The constraint shouldn't contain different type variables on both sides: " + subType + " <: " + superType "The constraint shouldn't contain different type variables on both sides: " + subType + " <: " + superType
@@ -312,22 +316,39 @@ public class ConstraintSystemImpl : ConstraintSystem {
boundKind: TypeBounds.BoundKind, boundKind: TypeBounds.BoundKind,
constraintPosition: ConstraintPosition constraintPosition: ConstraintPosition
) { ) {
var newConstrainingType = constrainingType
// Here we are handling the case when T! gets a bound Foo (or Foo?)
// In this case, type parameter T is supposed to get the bound Foo!
// Example:
// val c: Collection<Foo> = Collections.singleton(null : Foo?)
// Constraints for T are:
// Foo? <: T!
// Foo >: T!
// both Foo and Foo? transform to Foo! here
if (parameterType.isFlexible()) {
val typeVariable = parameterType.getCustomTypeVariable()
if (typeVariable != null) {
newConstrainingType = typeVariable.substitutionResult(constrainingType)
}
}
val typeBounds = getTypeBounds(parameterType) val typeBounds = getTypeBounds(parameterType)
if (!parameterType.isMarkedNullable() || !constrainingType.isMarkedNullable()) { if (!parameterType.isMarkedNullable() || !newConstrainingType.isMarkedNullable()) {
typeBounds.addBound(boundKind, constrainingType, constraintPosition) typeBounds.addBound(boundKind, newConstrainingType, constraintPosition)
return return
} }
// For parameter type T: // For parameter type T:
// constraint T? = Int? should transform to T >: Int and T <: Int? // constraint T? = Int? should transform to T >: Int and T <: Int?
// constraint T? >: Int? should transform to T >: Int // constraint T? >: Int? should transform to T >: Int
val notNullConstrainingType = TypeUtils.makeNotNullable(constrainingType) val notNullConstrainingType = TypeUtils.makeNotNullable(newConstrainingType)
if (boundKind == EXACT_BOUND || boundKind == LOWER_BOUND) { if (boundKind == EXACT_BOUND || boundKind == LOWER_BOUND) {
typeBounds.addBound(LOWER_BOUND, notNullConstrainingType, constraintPosition) typeBounds.addBound(LOWER_BOUND, notNullConstrainingType, constraintPosition)
} }
// constraint T? <: Int? should transform to T <: Int? // constraint T? <: Int? should transform to T <: Int?
if (boundKind == EXACT_BOUND || boundKind == UPPER_BOUND) { if (boundKind == EXACT_BOUND || boundKind == UPPER_BOUND) {
typeBounds.addBound(UPPER_BOUND, constrainingType, constraintPosition) typeBounds.addBound(UPPER_BOUND, newConstrainingType, constraintPosition)
} }
} }
@@ -30,6 +30,7 @@ import java.util.LinkedHashSet
import org.jetbrains.jet.lang.resolve.calls.inference.TypeBounds.BoundKind.* import org.jetbrains.jet.lang.resolve.calls.inference.TypeBounds.BoundKind.*
import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.ConstraintPosition import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.ConstraintPosition
import org.jetbrains.jet.utils.addIfNotNull import org.jetbrains.jet.utils.addIfNotNull
import org.jetbrains.jet.lang.types.singleBestRepresentative
public class TypeBoundsImpl( public class TypeBoundsImpl(
override val typeVariable: TypeParameterDescriptor, override val typeVariable: TypeParameterDescriptor,
@@ -106,10 +107,10 @@ public class TypeBoundsImpl(
} }
val exactBounds = filterBounds(bounds, EXACT_BOUND, values) val exactBounds = filterBounds(bounds, EXACT_BOUND, values)
if (exactBounds.size() == 1) { val bestFit = exactBounds.singleBestRepresentative()
val exactBound = exactBounds.iterator().next() if (bestFit != null) {
if (tryPossibleAnswer(exactBound)) { if (tryPossibleAnswer(bestFit)) {
return setOf(exactBound) return listOf(bestFit)
} }
} }
values.addAll(exactBounds) values.addAll(exactBounds)