[NI] Discriminate resulting type Nothing(?) at fixation stage

This commit is contained in:
Mikhail Zarechenskiy
2019-01-17 15:34:25 +03:00
parent 0b0e335cdd
commit 662e2287cc
7 changed files with 40 additions and 3 deletions
@@ -27,7 +27,8 @@ import org.jetbrains.kotlin.types.checker.intersectTypes
import org.jetbrains.kotlin.types.typeUtil.isPrimitiveNumberType
class ResultTypeResolver(
val typeApproximator: TypeApproximator
val typeApproximator: TypeApproximator,
val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle
) {
interface Context {
fun isProperType(type: UnwrappedType): Boolean
@@ -77,6 +78,9 @@ class ResultTypeResolver(
if (!isProperType(constraint.type)) continue
if (!checkConstraint(constraint.type, constraint.kind, resultType)) return false
}
if (!trivialConstraintTypeInferenceOracle.isSuitableResultedType(resultType)) return false
return true
}
@@ -19,6 +19,13 @@ class TrivialConstraintTypeInferenceOracle {
// TODO: probably we also can take into account `T <: Any(?)` constraints
return constraint.kind == ConstraintKind.LOWER && constraint.type.isNothingOrNullableNothing()
}
// This function controls the choice between sub and super result type
// Even that Nothing(?) is the most specific type for subtype, it doesn't bring valuable information to the user,
// therefore it is discriminated in favor of supertype
fun isSuitableResultedType(resultType: UnwrappedType): Boolean {
return !resultType.isNothingOrNullableNothing()
}
}
private fun UnwrappedType.isNothingOrNullableNothing(): Boolean =