FIR element serializer: drop duplicated approximation code
This commit is contained in:
+7
-10
@@ -550,19 +550,12 @@ class FirElementSerializer private constructor(
|
|||||||
fun typeId(type: ConeKotlinType): Int = typeTable[typeProto(type)]
|
fun typeId(type: ConeKotlinType): Int = typeTable[typeProto(type)]
|
||||||
|
|
||||||
private fun typeProto(typeRef: FirTypeRef, toSuper: Boolean = false): ProtoBuf.Type.Builder {
|
private fun typeProto(typeRef: FirTypeRef, toSuper: Boolean = false): ProtoBuf.Type.Builder {
|
||||||
val approximatedType = when (typeRef.coneType) {
|
return typeProto(typeRef.coneType, toSuper).also {
|
||||||
is ConeIntegerLiteralType,
|
|
||||||
is ConeDefinitelyNotNullType,
|
|
||||||
is ConeIntersectionType ->
|
|
||||||
typeRef.approximated(typeApproximator, toSuper)
|
|
||||||
else -> typeRef
|
|
||||||
}
|
|
||||||
return typeProto(approximatedType.coneType).also {
|
|
||||||
extension.serializeType(typeRef, it)
|
extension.serializeType(typeRef, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun typeProto(type: ConeKotlinType): ProtoBuf.Type.Builder {
|
private fun typeProto(type: ConeKotlinType, toSuper: Boolean = false): ProtoBuf.Type.Builder {
|
||||||
val builder = ProtoBuf.Type.newBuilder()
|
val builder = ProtoBuf.Type.newBuilder()
|
||||||
|
|
||||||
when (type) {
|
when (type) {
|
||||||
@@ -601,7 +594,11 @@ class FirElementSerializer private constructor(
|
|||||||
is ConeDefinitelyNotNullType,
|
is ConeDefinitelyNotNullType,
|
||||||
is ConeIntersectionType,
|
is ConeIntersectionType,
|
||||||
is ConeIntegerLiteralType -> {
|
is ConeIntegerLiteralType -> {
|
||||||
val approximatedType = typeApproximator.approximateToSubType(type, TypeApproximatorConfiguration.PublicDeclaration)
|
val approximatedType = if (toSuper) {
|
||||||
|
typeApproximator.approximateToSuperType(type, TypeApproximatorConfiguration.PublicDeclaration)
|
||||||
|
} else {
|
||||||
|
typeApproximator.approximateToSubType(type, TypeApproximatorConfiguration.PublicDeclaration)
|
||||||
|
}
|
||||||
assert(approximatedType != type && approximatedType is ConeKotlinType) {
|
assert(approximatedType != type && approximatedType is ConeKotlinType) {
|
||||||
"Approximation failed: ${type.render()}"
|
"Approximation failed: ${type.render()}"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user