Fix lost nullability in C-interop type aliases
^KT-43427
This commit is contained in:
committed by
Stanislav Erokhin
parent
bbbdf14ff0
commit
2953fb3970
+13
-2
@@ -326,6 +326,11 @@ private class MappingExtensions(
|
|||||||
Flag.Type.IS_NULLABLE.takeIf { nullable }
|
Flag.Type.IS_NULLABLE.takeIf { nullable }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val AbbreviatedType.expandedTypeFlags: Flags
|
||||||
|
get() = flagsOfNotNull(
|
||||||
|
Flag.Type.IS_NULLABLE.takeIf { isEffectivelyNullable() }
|
||||||
|
)
|
||||||
|
|
||||||
val TypealiasStub.flags: Flags
|
val TypealiasStub.flags: Flags
|
||||||
get() = flagsOfNotNull(
|
get() = flagsOfNotNull(
|
||||||
Flag.IS_PUBLIC
|
Flag.IS_PUBLIC
|
||||||
@@ -357,6 +362,13 @@ private class MappingExtensions(
|
|||||||
Flag.HAS_ANNOTATIONS.takeIf { annotations.isNotEmpty() }
|
Flag.HAS_ANNOTATIONS.takeIf { annotations.isNotEmpty() }
|
||||||
) or visibility.flags
|
) or visibility.flags
|
||||||
|
|
||||||
|
private tailrec fun StubType.isEffectivelyNullable(): Boolean =
|
||||||
|
when {
|
||||||
|
nullable -> true
|
||||||
|
this !is AbbreviatedType -> false
|
||||||
|
else -> underlyingType.isEffectivelyNullable()
|
||||||
|
}
|
||||||
|
|
||||||
fun AnnotationStub.map(): KmAnnotation {
|
fun AnnotationStub.map(): KmAnnotation {
|
||||||
fun Pair<String, String>.asAnnotationArgument() =
|
fun Pair<String, String>.asAnnotationArgument() =
|
||||||
(first to KmAnnotationArgument.StringValue(second)).takeIf { second.isNotEmpty() }
|
(first to KmAnnotationArgument.StringValue(second)).takeIf { second.isNotEmpty() }
|
||||||
@@ -467,8 +479,7 @@ private class MappingExtensions(
|
|||||||
km.arguments += typeArguments
|
km.arguments += typeArguments
|
||||||
}
|
}
|
||||||
if (shouldExpandTypeAliases) {
|
if (shouldExpandTypeAliases) {
|
||||||
// Abbreviated and expanded types have the same nullability.
|
KmType(expandedTypeFlags).also { km ->
|
||||||
KmType(flags).also { km ->
|
|
||||||
km.abbreviatedType = abbreviatedType
|
km.abbreviatedType = abbreviatedType
|
||||||
val kmUnderlyingType = underlyingType.map(true)
|
val kmUnderlyingType = underlyingType.map(true)
|
||||||
km.arguments += kmUnderlyingType.arguments
|
km.arguments += kmUnderlyingType.arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user