mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-19 08:31:29 +00:00
[Commonizer] Fix: Lost nullability in commonized type aliases
This commit is contained in:
@@ -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(
|
||||
classDescriptor: ClassDescriptor,
|
||||
arguments: List<CirTypeProjection>,
|
||||
|
||||
@@ -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
|
||||
fun forKnownUnderlyingType(underlyingType: CirClassOrTypeAliasType) = object : CommonizedTypeAliasTypeBuilder {
|
||||
override fun build(typeAliasId: ClassId, arguments: List<CirTypeProjection>, isMarkedNullable: Boolean) =
|
||||
CirTypeFactory.createTypeAliasType(
|
||||
override fun build(typeAliasId: ClassId, arguments: List<CirTypeProjection>, isMarkedNullable: Boolean): CirTypeAliasType {
|
||||
val underlyingTypeWithProperNullability = if (isMarkedNullable && !underlyingType.isMarkedNullable)
|
||||
CirTypeFactory.makeNullable(underlyingType)
|
||||
else
|
||||
underlyingType
|
||||
|
||||
return CirTypeFactory.createTypeAliasType(
|
||||
typeAliasId = typeAliasId,
|
||||
underlyingType = underlyingType, // TODO replace arguments???
|
||||
underlyingType = underlyingTypeWithProperNullability, // TODO replace arguments???
|
||||
arguments = arguments,
|
||||
isMarkedNullable = isMarkedNullable
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user