[Commonizer] Fix: Lost nullability in commonized type aliases
This commit is contained in:
+20
@@ -115,6 +115,26 @@ object CirTypeFactory {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun makeNullable(classOrTypeAliasType: CirClassOrTypeAliasType): CirClassOrTypeAliasType =
|
||||||
|
if (classOrTypeAliasType.isMarkedNullable)
|
||||||
|
classOrTypeAliasType
|
||||||
|
else
|
||||||
|
when (classOrTypeAliasType) {
|
||||||
|
is CirClassType -> createClassType(
|
||||||
|
classId = classOrTypeAliasType.classifierId,
|
||||||
|
outerType = classOrTypeAliasType.outerType,
|
||||||
|
visibility = classOrTypeAliasType.visibility,
|
||||||
|
arguments = classOrTypeAliasType.arguments,
|
||||||
|
isMarkedNullable = true
|
||||||
|
)
|
||||||
|
is CirTypeAliasType -> createTypeAliasType(
|
||||||
|
typeAliasId = classOrTypeAliasType.classifierId,
|
||||||
|
underlyingType = makeNullable(classOrTypeAliasType.underlyingType),
|
||||||
|
arguments = classOrTypeAliasType.arguments,
|
||||||
|
isMarkedNullable = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createClassTypeWithAllOuterTypes(
|
private fun createClassTypeWithAllOuterTypes(
|
||||||
classDescriptor: ClassDescriptor,
|
classDescriptor: ClassDescriptor,
|
||||||
arguments: List<CirTypeProjection>,
|
arguments: List<CirTypeProjection>,
|
||||||
|
|||||||
+9
-3
@@ -140,13 +140,19 @@ private class TypeAliasTypeCommonizer(private val cache: CirClassifiersCache) :
|
|||||||
|
|
||||||
// type alias don't needs to be commonized because it is from the standard library
|
// type alias don't needs to be commonized because it is from the standard library
|
||||||
fun forKnownUnderlyingType(underlyingType: CirClassOrTypeAliasType) = object : CommonizedTypeAliasTypeBuilder {
|
fun forKnownUnderlyingType(underlyingType: CirClassOrTypeAliasType) = object : CommonizedTypeAliasTypeBuilder {
|
||||||
override fun build(typeAliasId: ClassId, arguments: List<CirTypeProjection>, isMarkedNullable: Boolean) =
|
override fun build(typeAliasId: ClassId, arguments: List<CirTypeProjection>, isMarkedNullable: Boolean): CirTypeAliasType {
|
||||||
CirTypeFactory.createTypeAliasType(
|
val underlyingTypeWithProperNullability = if (isMarkedNullable && !underlyingType.isMarkedNullable)
|
||||||
|
CirTypeFactory.makeNullable(underlyingType)
|
||||||
|
else
|
||||||
|
underlyingType
|
||||||
|
|
||||||
|
return CirTypeFactory.createTypeAliasType(
|
||||||
typeAliasId = typeAliasId,
|
typeAliasId = typeAliasId,
|
||||||
underlyingType = underlyingType, // TODO replace arguments???
|
underlyingType = underlyingTypeWithProperNullability, // TODO replace arguments???
|
||||||
arguments = arguments,
|
arguments = arguments,
|
||||||
isMarkedNullable = isMarkedNullable
|
isMarkedNullable = isMarkedNullable
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user