[NI] Fix coercion to Unit for explicitly specified type argument

#KT-25424 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2018-11-21 18:22:28 +03:00
parent c6712ff861
commit 7a9fb3ca26
6 changed files with 28 additions and 4 deletions
@@ -25,7 +25,7 @@ class PostponedArgumentsAnalyzer(
// type can be proper if it not contains not fixed type variables
fun canBeProper(type: UnwrappedType): Boolean
fun hasUpperUnitConstraint(type: UnwrappedType): Boolean
fun hasUpperOrEqualUnitConstraint(type: UnwrappedType): Boolean
// mutable operations
fun addOtherSystem(otherSystem: ConstraintStorage)
@@ -76,7 +76,7 @@ class PostponedArgumentsAnalyzer(
c.canBeProper(rawReturnType) -> substitute(rawReturnType)
// For Unit-coercion
c.hasUpperUnitConstraint(rawReturnType) -> lambda.returnType.builtIns.unitType
c.hasUpperOrEqualUnitConstraint(rawReturnType) -> lambda.returnType.builtIns.unitType
else -> null
}
@@ -289,11 +289,11 @@ class NewConstraintSystemImpl(
}
// PostponedArgumentsAnalyzer.Context
override fun hasUpperUnitConstraint(type: UnwrappedType): Boolean {
override fun hasUpperOrEqualUnitConstraint(type: UnwrappedType): Boolean {
checkState(State.BUILDING, State.COMPLETION, State.FREEZED)
val constraints = storage.notFixedTypeVariables[type.constructor]?.constraints ?: return false
return constraints.any { it.kind == ConstraintKind.UPPER && it.type.isUnit() }
return constraints.any { (it.kind == ConstraintKind.UPPER || it.kind == ConstraintKind.EQUALITY) && it.type.isUnit() }
}
}