Map inline classes in generic argument position to theirs wrap classes
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// !LANGUAGE: +InlineClasses
|
||||||
|
|
||||||
|
class Inv<T>
|
||||||
|
|
||||||
|
inline class UInt(val value: Int)
|
||||||
|
|
||||||
|
object Test {
|
||||||
|
fun asNotNullTypeArgument(i: Inv<UInt>) {}
|
||||||
|
fun asInnerTypeArgument(i: Inv<Inv<UInt>>) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// method: Test::asNotNullTypeArgument
|
||||||
|
// jvm signature: (LInv;)V
|
||||||
|
// generic signature: (LInv<LUInt;>;)V
|
||||||
|
|
||||||
|
// method: Test::asInnerTypeArgument
|
||||||
|
// jvm signature: (LInv;)V
|
||||||
|
// generic signature: (LInv<LInv<LUInt;>;>;)V
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// !LANGUAGE: +InlineClasses
|
||||||
|
|
||||||
|
inline class Foo(val b: Bar)
|
||||||
|
inline class Bar(val i: Int)
|
||||||
|
|
||||||
|
object Test {
|
||||||
|
fun simple(f: Foo) {}
|
||||||
|
fun listOfFoo(f: List<Foo>) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// method: Test::simple
|
||||||
|
// jvm signature: (I)V
|
||||||
|
// generic signature: null
|
||||||
|
|
||||||
|
// method: Test::listOfFoo
|
||||||
|
// jvm signature: (Ljava/util/List;)V
|
||||||
|
// generic signature: (Ljava/util/List<LFoo;>;)V
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
// !LANGUAGE: +InlineClasses
|
||||||
|
|
||||||
|
class Inv<T>
|
||||||
|
|
||||||
|
inline class AsList<T>(val list: List<T>)
|
||||||
|
inline class UInt(val value: Int)
|
||||||
|
|
||||||
|
object Test {
|
||||||
|
fun withInlineClassArgument(a: AsList<UInt>) {}
|
||||||
|
fun withListOfInlineClassArgument(a: AsList<List<UInt>>) {}
|
||||||
|
fun withInnerGenericInlineClass(a: AsList<AsList<List<UInt>>>) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// method: Test::withInlineClassArgument
|
||||||
|
// jvm signature: (Ljava/util/List;)V
|
||||||
|
// generic signature: (Ljava/util/List<LUInt;>;)V
|
||||||
|
|
||||||
|
// method: Test::withListOfInlineClassArgument
|
||||||
|
// jvm signature: (Ljava/util/List;)V
|
||||||
|
// generic signature: (Ljava/util/List<+Ljava/util/List<LUInt;>;>;)V
|
||||||
|
|
||||||
|
// method: Test::withInnerGenericInlineClass
|
||||||
|
// jvm signature: (Ljava/util/List;)V
|
||||||
|
// generic signature: (Ljava/util/List<LAsList<Ljava/util/List<Ljava/lang/Integer;>;>;>;)V
|
||||||
+18
@@ -582,6 +582,24 @@ public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineClassAsGenericArgument.kt")
|
||||||
|
public void testInlineClassAsGenericArgument() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/writeSignature/inlineClasses/inlineClassAsGenericArgument.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineClassBasedOnOtherInlineClass.kt")
|
||||||
|
public void testInlineClassBasedOnOtherInlineClass() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/writeSignature/inlineClasses/inlineClassBasedOnOtherInlineClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineClassWithComplexSubstitutedType.kt")
|
||||||
|
public void testInlineClassWithComplexSubstitutedType() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/writeSignature/inlineClasses/inlineClassWithComplexSubstitutedType.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullableInlineClassType.kt")
|
@TestMetadata("nullableInlineClassType.kt")
|
||||||
public void testNullableInlineClassType() throws Exception {
|
public void testNullableInlineClassType() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/writeSignature/inlineClasses/nullableInlineClassType.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/writeSignature/inlineClasses/nullableInlineClassType.kt");
|
||||||
|
|||||||
@@ -5,12 +5,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.kotlin
|
package org.jetbrains.kotlin.load.kotlin
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.resolve.isInlineClassType
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
class TypeMappingMode private constructor(
|
class TypeMappingMode private constructor(
|
||||||
val needPrimitiveBoxing: Boolean = true,
|
val needPrimitiveBoxing: Boolean = true,
|
||||||
val needInlineClassWrapping: Boolean = false,
|
val needInlineClassWrapping: Boolean = true,
|
||||||
val isForAnnotationParameter: Boolean = false,
|
val isForAnnotationParameter: Boolean = false,
|
||||||
// Here DeclarationSiteWildcards means wildcard generated because of declaration-site variance
|
// Here DeclarationSiteWildcards means wildcard generated because of declaration-site variance
|
||||||
val skipDeclarationSiteWildcards: Boolean = false,
|
val skipDeclarationSiteWildcards: Boolean = false,
|
||||||
@@ -38,7 +39,7 @@ class TypeMappingMode private constructor(
|
|||||||
* kotlin.Int is mapped to I
|
* kotlin.Int is mapped to I
|
||||||
*/
|
*/
|
||||||
@JvmField
|
@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
|
* kotlin.Int is mapped to I
|
||||||
@@ -120,7 +121,9 @@ class TypeMappingMode private constructor(
|
|||||||
skipDeclarationSiteWildcards = !canBeUsedInSupertypePosition,
|
skipDeclarationSiteWildcards = !canBeUsedInSupertypePosition,
|
||||||
skipDeclarationSiteWildcardsIfPossible = true,
|
skipDeclarationSiteWildcardsIfPossible = true,
|
||||||
genericContravariantArgumentMode = contravariantArgumentMode,
|
genericContravariantArgumentMode = contravariantArgumentMode,
|
||||||
genericInvariantArgumentMode = invariantArgumentMode)
|
genericInvariantArgumentMode = invariantArgumentMode,
|
||||||
|
needInlineClassWrapping = !type.isInlineClassType()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -140,4 +143,10 @@ class TypeMappingMode private constructor(
|
|||||||
Variance.INVARIANT -> genericInvariantArgumentMode ?: this
|
Variance.INVARIANT -> genericInvariantArgumentMode ?: this
|
||||||
else -> genericArgumentMode ?: 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.platform.JavaToKotlinClassMap
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
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.JvmClassName
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||||
import org.jetbrains.kotlin.resolve.substitutedUnderlyingType
|
import org.jetbrains.kotlin.resolve.substitutedUnderlyingType
|
||||||
@@ -133,7 +134,8 @@ fun <T : Any> mapType(
|
|||||||
if (descriptor.isInline && !mode.needInlineClassWrapping) {
|
if (descriptor.isInline && !mode.needInlineClassWrapping) {
|
||||||
val typeForMapping = computeUnderlyingType(kotlinType)
|
val typeForMapping = computeUnderlyingType(kotlinType)
|
||||||
if (typeForMapping != null) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user