[NI] Remove capturing from supertypes during computation of CST

This commit is contained in:
Mikhail Zarechenskiy
2019-09-16 03:14:40 +03:00
parent e8907c078d
commit b30a9e1d3e
12 changed files with 114 additions and 11 deletions
@@ -257,17 +257,22 @@ object NewCommonSuperTypeCalculator {
val parameter = constructor.getParameter(index)
var thereIsStar = false
val typeProjections = correspondingSuperTypes.mapNotNull {
it.getArgumentOrNull(index)?.let { typeArgument ->
when {
typeArgument.isStarProjection() -> {
thereIsStar = true
null
}
val typeArgumentFromSupertype = it.getArgumentOrNull(index) ?: return@mapNotNull null
typeArgument.getType().lowerBoundIfFlexible().isStubType() -> null
// We have to uncapture types with status FOR_SUBTYPING because such captured types are creating during
// `findCorrespondingSupertypes` call. Normally, we shouldn't create intermediate captured types here, it's needed only
// to check subtyping. It'll be fixed but for a while we do this uncapturing here
val typeArgument = uncaptureFromSubtyping(typeArgumentFromSupertype)
else -> typeArgument
when {
typeArgument.isStarProjection() -> {
thereIsStar = true
null
}
typeArgument.getType().lowerBoundIfFlexible().isStubType() -> null
else -> typeArgument
}
}
@@ -295,6 +300,13 @@ object NewCommonSuperTypeCalculator {
return createSimpleType(constructor, arguments, nullable = false)
}
private fun TypeSystemCommonSuperTypesContext.uncaptureFromSubtyping(typeArgument: TypeArgumentMarker): TypeArgumentMarker {
val capturedType = typeArgument.getType().asSimpleType()?.asCapturedType() ?: return typeArgument
if (capturedType.captureStatus() != CaptureStatus.FOR_SUBTYPING) return typeArgument
return capturedType.typeConstructor().projection()
}
// no star projections in arguments
private fun TypeSystemCommonSuperTypesContext.calculateArgument(
parameter: TypeParameterMarker,