Union type attributes for common super type calculation

This commit is contained in:
Irene Dea
2021-10-13 14:37:31 -07:00
committed by Dmitriy Novozhilov
parent db471ca61e
commit 56d817b49f
11 changed files with 44 additions and 150 deletions
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.types.model.*
object NewCommonSuperTypeCalculator {
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0
return commonSuperType(types, -maxDepth, true)
return commonSuperType(types, -maxDepth, true).replaceTypeAttributes(unionTypeAttributes(types))
}
private fun TypeSystemCommonSuperTypesContext.commonSuperType(
@@ -80,7 +80,7 @@ class PostponedArgumentInputTypesResolver(
}
}
val annotations = functionalTypesFromConstraints?.map { it.type.getAnnotations() }?.flatten()?.distinct()
val annotations = functionalTypesFromConstraints?.map { it.type.getAttributes() }?.flatten()?.distinct()
val extensionFunctionTypePresentInConstraints = functionalTypesFromConstraints?.any { it.type.isExtensionFunctionType() } == true
@@ -139,7 +139,11 @@ class MutableVariableWithConstraints private constructor(
return false
return when (old.kind) {
ConstraintKind.EQUALITY -> true
ConstraintKind.EQUALITY -> {
with(context) {
old.type.getAttributes() == new.type.getAttributes()
}
}
ConstraintKind.LOWER -> new.kind.isLower()
ConstraintKind.UPPER -> new.kind.isUpper()
}