Fix coercion to Unit with equal Nothing constraint

#KT-39669 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-06-23 01:38:04 +03:00
parent a06c8786df
commit e7cee9c6e1
8 changed files with 152 additions and 3 deletions
@@ -35,6 +35,7 @@ class PostponedArgumentsAnalyzer(
fun canBeProper(type: KotlinTypeMarker): Boolean
fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean
fun hasEqualNothingConstraint(type: KotlinTypeMarker): Boolean
// mutable operations
fun addOtherSystem(otherSystem: ConstraintStorage)
@@ -122,7 +123,7 @@ class PostponedArgumentsAnalyzer(
c.canBeProper(rawReturnType) -> substitute(rawReturnType)
// For Unit-coercion
c.hasUpperOrEqualUnitConstraint(rawReturnType) -> builtIns.unitType
c.hasUpperOrEqualUnitConstraint(rawReturnType) && !c.hasEqualNothingConstraint(rawReturnType) -> builtIns.unitType
else -> null
}
@@ -386,9 +386,13 @@ class NewConstraintSystemImpl(
// PostponedArgumentsAnalyzer.Context
override fun hasUpperOrEqualUnitConstraint(type: KotlinTypeMarker): Boolean {
checkState(State.BUILDING, State.COMPLETION, State.FREEZED)
val constraints = storage.notFixedTypeVariables[type.typeConstructor()]?.constraints ?: return false
return constraints.any { (it.kind == ConstraintKind.UPPER || it.kind == ConstraintKind.EQUALITY) && it.type.isUnit() }
}
override fun hasEqualNothingConstraint(type: KotlinTypeMarker): Boolean {
checkState(State.BUILDING, State.COMPLETION, State.FREEZED)
val constraints = storage.notFixedTypeVariables[type.typeConstructor()]?.constraints ?: return false
return constraints.any { (it.kind == ConstraintKind.EQUALITY) && it.type.isNothing() }
}
}