[NI] Discriminate resulting type Nothing(?) at fixation stage
This commit is contained in:
+5
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user