Fix union related failures.
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
a98e2c4e03
commit
13bff10567
@@ -405,16 +405,19 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
return (types as List<ConeKotlinType>).map { it.attributes }.reduce { x, y -> x.union(y) }.toList()
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
||||
private fun AnnotationMarker.isCustomAttribute(): Boolean {
|
||||
val compilerAttributes = CompilerConeAttributes.classIdByCompilerAttribute
|
||||
return this !in compilerAttributes && this !is CustomAnnotationTypeAttribute
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.replaceCustomAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
||||
require(this is ConeKotlinType)
|
||||
if (newAttributes.isEmpty()) return this
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return createSimpleType(
|
||||
this.typeConstructor(),
|
||||
this.getArguments(),
|
||||
this.isNullable,
|
||||
this.isExtensionFunctionType,
|
||||
newAttributes as List<ConeAttribute<*>>
|
||||
val newCustomAttributes = (newAttributes as List<ConeAttribute<*>>).filter { it.isCustomAttribute() }
|
||||
val attributesToKeep = this.attributes.filterNot { it.isCustomAttribute() }
|
||||
return withAttributes(
|
||||
ConeAttributes.create(newCustomAttributes + attributesToKeep),
|
||||
this@ConeInferenceContext
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,10 @@ fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes, typeSystem
|
||||
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes)
|
||||
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withAttributes(attributes, typeSystemContext))
|
||||
is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes)
|
||||
is ConeRawType -> ConeRawType(
|
||||
lowerBound.withAttributes(attributes, typeSystemContext),
|
||||
upperBound.withAttributes(attributes, typeSystemContext)
|
||||
)
|
||||
is ConeFlexibleType -> ConeFlexibleType(
|
||||
lowerBound.withAttributes(attributes, typeSystemContext),
|
||||
upperBound.withAttributes(attributes, typeSystemContext)
|
||||
|
||||
@@ -383,7 +383,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? =
|
||||
irBuiltIns.intType as IrSimpleType
|
||||
|
||||
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker = this
|
||||
override fun KotlinTypeMarker.replaceCustomAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker = this
|
||||
|
||||
override fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker> = emptyList()
|
||||
|
||||
|
||||
+1
-1
@@ -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).let { it.replaceTypeAttributes(unionTypeAttributes(listOf(it) + types)) }
|
||||
return commonSuperType(types, -maxDepth, true).replaceCustomAttributes(unionTypeAttributes(types))
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.commonSuperType(
|
||||
|
||||
@@ -136,7 +136,7 @@ interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeF
|
||||
|
||||
fun unionTypeAttributes(types: List<KotlinTypeMarker>): List<AnnotationMarker>
|
||||
|
||||
fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker
|
||||
fun KotlinTypeMarker.replaceCustomAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker
|
||||
}
|
||||
|
||||
// This interface is only used to declare that implementing class is supposed to be used as a TypeSystemInferenceExtensionContext component
|
||||
|
||||
@@ -10,9 +10,9 @@ import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class AnnotationsTypeAttribute(val annotations: Annotations) : TypeAttribute<AnnotationsTypeAttribute>() {
|
||||
override fun union(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute = this
|
||||
override fun union(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute? = null
|
||||
|
||||
override fun intersect(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute = this
|
||||
override fun intersect(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute? = null
|
||||
|
||||
override fun add(other: AnnotationsTypeAttribute?): AnnotationsTypeAttribute {
|
||||
if (other == null) return this
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.unsubstitutedUnderlyingType
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSignedOrUnsignedNumberType as classicIsSignedOrUnsignedNumberType
|
||||
@@ -644,12 +645,13 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
return (types as List<KotlinType>).map { it.unwrap().attributes }.reduce { x, y -> x.union(y) }.toList()
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.replaceTypeAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
||||
override fun KotlinTypeMarker.replaceCustomAttributes(newAttributes: List<AnnotationMarker>): KotlinTypeMarker {
|
||||
require(this is KotlinType)
|
||||
if (newAttributes.isEmpty()) return this
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val attributes = (newAttributes as List<TypeAttribute<*>>).filterNot { it is AnnotationsTypeAttribute }.toMutableList()
|
||||
attributes.addIfNotNull(this.attributes.annotationsAttribute)
|
||||
return this.unwrap().replaceAttributes(
|
||||
TypeAttributes.create(newAttributes as List<TypeAttribute<*>>)
|
||||
TypeAttributes.create(attributes)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user