Capture types only on the top level
This commit is contained in:
+12
-1
@@ -56,13 +56,14 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
private val typeParameterBounds = LinkedHashMap<TypeParameterDescriptor, TypeBoundsImpl>()
|
||||
private val errorConstraintPositions = HashSet<ConstraintPosition>()
|
||||
private var hasErrorInConstrainingTypes: Boolean = false
|
||||
private var cannotCaptureTypesError: Boolean = false
|
||||
|
||||
private val constraintSystemStatus = object : ConstraintSystemStatus {
|
||||
// for debug ConstraintsUtil.getDebugMessageForStatus might be used
|
||||
|
||||
override fun isSuccessful() = !hasContradiction() && !hasUnknownParameters()
|
||||
|
||||
override fun hasContradiction() = hasTypeConstructorMismatch() || hasConflictingConstraints()
|
||||
override fun hasContradiction() = hasTypeConstructorMismatch() || hasConflictingConstraints() || hasCannotCaptureTypesError()
|
||||
|
||||
override fun hasViolatedUpperBound(): Boolean {
|
||||
if (isSuccessful()) return false
|
||||
@@ -104,6 +105,8 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
}
|
||||
|
||||
override fun hasErrorInConstrainingTypes() = hasErrorInConstrainingTypes
|
||||
|
||||
override fun hasCannotCaptureTypesError() = cannotCaptureTypesError
|
||||
}
|
||||
|
||||
private fun getParameterToInferredValueMap(typeParameterBounds: Map<TypeParameterDescriptor, TypeBoundsImpl>, getDefaultTypeProjection: Function1<TypeParameterDescriptor, TypeProjection>): Map<TypeParameterDescriptor, TypeProjection> {
|
||||
@@ -195,6 +198,7 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
newSystem.errorConstraintPositions.addAll(errorConstraintPositions.filter(filterConstraintPosition))
|
||||
//todo if 'filterConstraintPosition' is not trivial, it's incorrect to just copy 'hasErrorInConstrainingTypes'
|
||||
newSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes
|
||||
newSystem.cannotCaptureTypesError = cannotCaptureTypesError
|
||||
return newSystem
|
||||
}
|
||||
|
||||
@@ -210,7 +214,10 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
|
||||
private fun addConstraint(constraintKind: ConstraintKind, subType: JetType?, superType: JetType?, constraintPosition: ConstraintPosition) {
|
||||
val typeCheckingProcedure = TypeCheckingProcedure(object : TypingConstraints {
|
||||
private var isTopLevel = true
|
||||
|
||||
override fun assertEqualTypes(a: JetType, b: JetType, typeCheckingProcedure: TypeCheckingProcedure): Boolean {
|
||||
isTopLevel = false
|
||||
doAddConstraint(EQUAL, a, b, constraintPosition, typeCheckingProcedure)
|
||||
return true
|
||||
|
||||
@@ -221,12 +228,16 @@ public class ConstraintSystemImpl : ConstraintSystem {
|
||||
}
|
||||
|
||||
override fun assertSubtype(subtype: JetType, supertype: JetType, typeCheckingProcedure: TypeCheckingProcedure): Boolean {
|
||||
isTopLevel = false
|
||||
doAddConstraint(SUB_TYPE, subtype, supertype, constraintPosition, typeCheckingProcedure)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun capture(typeVariable: JetType, typeProjection: TypeProjection): Boolean {
|
||||
if (isMyTypeVariable(typeVariable) && constraintPosition.isCaptureAllowed()) {
|
||||
if (!isTopLevel) {
|
||||
cannotCaptureTypesError = true
|
||||
}
|
||||
generateTypeParameterCaptureConstraint(typeVariable, typeProjection, constraintPosition)
|
||||
return true
|
||||
}
|
||||
|
||||
+3
@@ -85,4 +85,7 @@ public trait ConstraintSystemStatus {
|
||||
* Is used not to generate type inference error if there was one in argument types.
|
||||
*/
|
||||
public fun hasErrorInConstrainingTypes(): Boolean
|
||||
|
||||
//todo comment
|
||||
public fun hasCannotCaptureTypesError(): Boolean
|
||||
}
|
||||
Reference in New Issue
Block a user