Use underlying type when computing type mapping mode for inline classes

This commit is contained in:
Dmitry Petrov
2018-08-14 12:46:28 +03:00
parent 948e72f653
commit 8e95ecb821
9 changed files with 117 additions and 2 deletions
@@ -103,6 +103,13 @@ class TypeMappingMode private constructor(
): TypeMappingMode {
if (type.arguments.isEmpty()) return DEFAULT
if (type.isInlineClassType() && shouldUseUnderlyingType(type)) {
val underlyingType = computeUnderlyingType(type)
if (underlyingType != null) {
return getOptimalModeForSignaturePart(underlyingType, isForAnnotationParameter, canBeUsedInSupertypePosition)
}
}
val contravariantArgumentMode =
if (!canBeUsedInSupertypePosition)
TypeMappingMode(
@@ -240,7 +240,7 @@ private fun <T : Any> mapBuiltInType(
return null
}
private fun computeUnderlyingType(inlineClassType: KotlinType): KotlinType? {
internal fun computeUnderlyingType(inlineClassType: KotlinType): KotlinType? {
if (!shouldUseUnderlyingType(inlineClassType)) return null
val descriptor = inlineClassType.unsubstitutedUnderlyingType()?.constructor?.declarationDescriptor ?: return null
@@ -250,7 +250,7 @@ private fun computeUnderlyingType(inlineClassType: KotlinType): KotlinType? {
inlineClassType.substitutedUnderlyingType()
}
private fun shouldUseUnderlyingType(inlineClassType: KotlinType): Boolean {
internal fun shouldUseUnderlyingType(inlineClassType: KotlinType): Boolean {
val underlyingType = inlineClassType.unsubstitutedUnderlyingType() ?: return false
return !inlineClassType.isMarkedNullable ||