Take into account possible passed old captured type in isCapturedTypeFromSubtyping check

^KT-48590 Fixed
This commit is contained in:
Victor Petukhov
2021-10-04 18:31:40 +03:00
parent d015d3bc0e
commit 43e9c1223a
6 changed files with 52 additions and 3 deletions
@@ -307,13 +307,18 @@ class ConstraintInjector(
override fun addEqualityConstraint(typeVariable: TypeConstructorMarker, type: KotlinTypeMarker) =
addConstraint(typeVariable, type, EQUALITY, false)
private fun isCapturedTypeFromSubtyping(type: KotlinTypeMarker) =
when ((type as? CapturedTypeMarker)?.captureStatus()) {
null, CaptureStatus.FROM_EXPRESSION -> false
private fun isCapturedTypeFromSubtyping(type: KotlinTypeMarker): Boolean {
val capturedType = type as? CapturedTypeMarker ?: return false
if (capturedType.isOldCapturedType()) return false
return when (capturedType.captureStatus()) {
CaptureStatus.FROM_EXPRESSION -> false
CaptureStatus.FOR_SUBTYPING -> true
CaptureStatus.FOR_INCORPORATION ->
error("Captured type for incorporation shouldn't escape from incorporation: $type\n" + renderBaseConstraint())
}
}
private fun addConstraint(
typeVariableConstructor: TypeConstructorMarker,