ResultTypeResolver: don't allow Nothing as ILT subtype

#KT-58379 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-05-03 11:09:32 +02:00
committed by Space Team
parent 6ae648f6f6
commit 1c7ffb3276
3 changed files with 4 additions and 27 deletions
@@ -94,12 +94,13 @@ class ResultTypeResolver(
// and the second one from UPPER/LOWER constraints (subType/superType based)
// The logic of choice here is:
// - if one type is null, we return another one
// - we return type from UPPER/LOWER constraints if it's more precise
// - we return type from UPPER/LOWER constraints if it's more precise (in fact, only Int/Short/Byte/Long is allowed here)
// - otherwise we return ILT-based type
return when {
resultTypeFromEqualConstraint == null -> resultTypeFromDirection
resultTypeFromDirection == null -> resultTypeFromEqualConstraint
AbstractTypeChecker.isSubtypeOf(c, resultTypeFromDirection, resultTypeFromEqualConstraint) -> resultTypeFromDirection
with(c) { !resultTypeFromDirection.typeConstructor().isNothingConstructor() } &&
AbstractTypeChecker.isSubtypeOf(c, resultTypeFromDirection, resultTypeFromEqualConstraint) -> resultTypeFromDirection
else -> resultTypeFromEqualConstraint
}
}
@@ -1,25 +0,0 @@
// WITH_STDLIB
import Cause.*
typealias ChallengeFunction = suspend (String) -> Unit
enum class Cause {
FIRST,
SECOND,
ERROR,
LAST
}
class Some {
internal val register = mutableListOf<Pair<Cause, ChallengeFunction>>()
internal val challenges: List<ChallengeFunction>
get() = <!NEW_INFERENCE_ERROR!>register.filter { it.first != ERROR }.sortedBy {
when (it.first) {
FIRST -> 1
SECOND -> 2
else -> throw AssertionError()
}
}<!>.map { it.second }
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// WITH_STDLIB
import Cause.*