[FE] Show causing types in the INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION diagnostic

This commit is contained in:
Victor Petukhov
2022-05-25 18:14:19 +02:00
committed by teamcity
parent 6a34b184ac
commit 867ad24c86
51 changed files with 217 additions and 163 deletions
@@ -67,10 +67,11 @@ class ClassicTypeSystemContextForCS(
}
override fun TypeSubstitutorMarker.safeSubstitute(type: KotlinTypeMarker): KotlinTypeMarker {
require(type is UnwrappedType, type::errorMessage)
require(type is KotlinType, type::errorMessage)
val unwrappedType = type.unwrap()
return when (this) {
is NewTypeSubstitutor -> safeSubstitute(type)
is TypeSubstitutor -> safeSubstitute(type, Variance.INVARIANT)
is NewTypeSubstitutor -> safeSubstitute(unwrappedType)
is TypeSubstitutor -> safeSubstitute(unwrappedType, Variance.INVARIANT)
else -> error(this.errorMessage())
}
}
@@ -902,15 +902,21 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
continue
}
else -> {
val emptyIntersectionKind = constraintSystem.getEmptyIntersectionTypeKind(upperTypes).takeIf { it.isDefinitelyEmpty() }
?: continue
val emptyIntersectionTypeInfo = constraintSystem.getEmptyIntersectionTypeKind(upperTypes) ?: continue
val isInferredEmptyIntersectionForbidden = callComponents.languageVersionSettings.supportsFeature(
LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection
)
val errorFactory =
if (isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning
addError(errorFactory(upperTypes, variableWithConstraints.typeVariable, emptyIntersectionKind))
addError(
errorFactory(
upperTypes,
emptyIntersectionTypeInfo.casingTypes.toList(),
variableWithConstraints.typeVariable,
emptyIntersectionTypeInfo.kind
)
)
}
}
}