Map inline classes in generic argument position to theirs wrap classes

This commit is contained in:
Mikhail Zarechenskiy
2018-02-09 08:26:25 +03:00
parent 1d16d21dbb
commit a8a9f774d0
6 changed files with 92 additions and 4 deletions
@@ -5,12 +5,13 @@
package org.jetbrains.kotlin.load.kotlin
import org.jetbrains.kotlin.resolve.isInlineClassType
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
class TypeMappingMode private constructor(
val needPrimitiveBoxing: Boolean = true,
val needInlineClassWrapping: Boolean = false,
val needInlineClassWrapping: Boolean = true,
val isForAnnotationParameter: Boolean = false,
// Here DeclarationSiteWildcards means wildcard generated because of declaration-site variance
val skipDeclarationSiteWildcards: Boolean = false,
@@ -38,7 +39,7 @@ class TypeMappingMode private constructor(
* kotlin.Int is mapped to I
*/
@JvmField
val DEFAULT = TypeMappingMode(genericArgumentMode = GENERIC_ARGUMENT, needPrimitiveBoxing = false)
val DEFAULT = TypeMappingMode(genericArgumentMode = GENERIC_ARGUMENT, needPrimitiveBoxing = false, needInlineClassWrapping = false)
/**
* kotlin.Int is mapped to I
@@ -120,7 +121,9 @@ class TypeMappingMode private constructor(
skipDeclarationSiteWildcards = !canBeUsedInSupertypePosition,
skipDeclarationSiteWildcardsIfPossible = true,
genericContravariantArgumentMode = contravariantArgumentMode,
genericInvariantArgumentMode = invariantArgumentMode)
genericInvariantArgumentMode = invariantArgumentMode,
needInlineClassWrapping = !type.isInlineClassType()
)
}
@JvmStatic
@@ -140,4 +143,10 @@ class TypeMappingMode private constructor(
Variance.INVARIANT -> genericInvariantArgumentMode ?: this
else -> genericArgumentMode ?: this
}
fun wrapInlineClassesMode(): TypeMappingMode =
TypeMappingMode(
needPrimitiveBoxing, true, isForAnnotationParameter, skipDeclarationSiteWildcards, skipDeclarationSiteWildcardsIfPossible,
genericArgumentMode, kotlinCollectionsToJavaCollections, genericContravariantArgumentMode, genericInvariantArgumentMode
)
}
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.isInlineClassType
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
import org.jetbrains.kotlin.resolve.substitutedUnderlyingType
@@ -133,7 +134,8 @@ fun <T : Any> mapType(
if (descriptor.isInline && !mode.needInlineClassWrapping) {
val typeForMapping = computeUnderlyingType(kotlinType)
if (typeForMapping != null) {
return mapType(typeForMapping, factory, mode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType)
val newMode = if (typeForMapping.isInlineClassType()) mode else mode.wrapInlineClassesMode()
return mapType(typeForMapping, factory, newMode, typeMappingConfiguration, descriptorTypeWriter, writeGenericType)
}
}