From ddfa94e7e94c56ce8bfb922fdf03d9030791e4de Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 7 Jul 2021 13:04:59 +0200 Subject: [PATCH] Support Nothing type in typeOf The proper support will come in KT-15518, but that would be a breaking change even for stable Kotlin without kotlin-reflect. Before that issue is fixed, represent Nothing in types with the Void class, and use a flag in the no-reflect implementation to remember that it's not actually the Void class itself. #KT-39166 Fixed --- .../jetbrains/kotlin/codegen/inline/typeOf.kt | 2 + .../FirBlackBoxCodegenTestGenerated.java | 24 ++++++++++ .../typeOf/noReflect/nothing_after.kt | 48 +++++++++++++++++++ .../typeOf/noReflect/nothing_before.kt | 44 +++++++++++++++++ .../box/reflection/typeOf/nothing_after.kt | 47 ++++++++++++++++++ .../box/reflection/typeOf/nothing_before.kt | 44 +++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 24 ++++++++++ .../IrBlackBoxCodegenTestGenerated.java | 24 ++++++++++ .../LightAnalysisModeTestGenerated.java | 20 ++++++++ .../jvm/internal/ReflectionFactoryImpl.java | 5 ++ .../kotlin/reflect/jvm/internal/typeOfImpl.kt | 9 ++++ .../kotlin/jvm/internal/Reflection.java | 5 ++ .../jvm/internal/ReflectionFactory.java | 20 +++++--- .../kotlin/jvm/internal/TypeReference.kt | 24 +++++++--- .../kotlin-stdlib-runtime-merged.txt | 13 ++++- 15 files changed, 338 insertions(+), 15 deletions(-) create mode 100644 compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt create mode 100644 compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt create mode 100644 compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt create mode 100644 compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt index 3ff2fdf4135..47ffb6e100f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt @@ -98,6 +98,8 @@ fun TypeSystemCommonBackendContext.generateTypeOf( if (intrinsicsSupport.state.stableTypeOf) { if (intrinsicsSupport.isMutableCollectionType(type)) { v.invokestatic(REFLECTION, "mutableCollectionType", Type.getMethodDescriptor(K_TYPE, K_TYPE), false) + } else if (type.typeConstructor().isNothingConstructor()) { + v.invokestatic(REFLECTION, "nothingType", Type.getMethodDescriptor(K_TYPE, K_TYPE), false) } if (type.isFlexible()) { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index c42cca42c4e..05fac697bd2 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -37509,6 +37509,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/reflection/typeOf/mutableCollections_before.kt"); } + @Test + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt"); + } + + @Test + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt"); + } + @Test @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { @@ -37582,6 +37594,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/mutableCollections_before.kt"); } + @Test + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt"); + } + + @Test + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt"); + } + @Test @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { diff --git a/compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt b/compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt new file mode 100644 index 00000000000..be540ca5128 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt @@ -0,0 +1,48 @@ +// !API_VERSION: LATEST +// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: box.kt + +package test + +import kotlin.reflect.KType +import kotlin.reflect.KTypeParameter +import kotlin.reflect.typeOf +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +class C(v: V) + +fun nothingBound() = + (typeOf>().arguments.single().type!!.classifier as KTypeParameter).upperBounds.single() + +fun check(expected: String, actual: KType) { + assertEquals(expected + " (Kotlin reflection is not available)", actual.toString()) +} + +fun box(): String { + check("test.C", typeOf>()) + check("test.C", typeOf>()) + check("kotlin.Nothing?", nothingBound()) + + // String representation of platform types does not differ from non-nullable types in the stdlib implementation (without reflect). + check("test.C", returnTypeOf { C(J.platformType()) }) + + // Such type's classifier is still Void::class, until KT-15518 is fixed. + // TODO: support a special KClass instance for Nothing (KT-15518). + assertEquals(Void::class, typeOf>().arguments.single().type!!.classifier) + + assertNotEquals(typeOf>(), typeOf>()) + + return "OK" +} + +inline fun returnTypeOf(block: () -> Z) = + typeOf() + +// FILE: J.java + +public class J { + public static X platformType() { return null; } +} diff --git a/compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt b/compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt new file mode 100644 index 00000000000..f9c791b1e19 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt @@ -0,0 +1,44 @@ +// !API_VERSION: 1.5 +// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: box.kt + +package test + +import kotlin.reflect.KType +import kotlin.reflect.KTypeParameter +import kotlin.reflect.typeOf +import kotlin.test.assertEquals + +class C(v: V) + +fun nothingBound() = + (typeOf>().arguments.single().type!!.classifier as KTypeParameter).upperBounds.single() + +fun check(expected: String, actual: KType) { + assertEquals(expected + " (Kotlin reflection is not available)", actual.toString()) +} + +fun box(): String { + check("test.C", typeOf>()) + check("test.C", typeOf>()) + check("java.lang.Void?", nothingBound()) + + check("test.C", returnTypeOf { C(J.platformType()) }) + + assertEquals(Void::class, typeOf>().arguments.single().type!!.classifier) + + assertEquals(typeOf>(), typeOf>()) + + return "OK" +} + +inline fun returnTypeOf(block: () -> Z) = + typeOf() + +// FILE: J.java + +public class J { + public static X platformType() { return null; } +} diff --git a/compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt b/compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt new file mode 100644 index 00000000000..5eb4b40ea35 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt @@ -0,0 +1,47 @@ +// !API_VERSION: LATEST +// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi +// TARGET_BACKEND: JVM +// WITH_REFLECT +// FILE: box.kt + +package test + +import kotlin.reflect.KType +import kotlin.reflect.KTypeParameter +import kotlin.reflect.typeOf +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +class C(v: V) + +fun nothingBound() = + (typeOf>().arguments.single().type!!.classifier as KTypeParameter).upperBounds.single() + +fun check(expected: String, actual: KType) { + assertEquals(expected, actual.toString()) +} + +fun box(): String { + check("test.C", typeOf>()) + check("test.C", typeOf>()) + check("kotlin.Nothing?", nothingBound()) + + check("test.C", returnTypeOf { C(J.platformType()) }) + + // Such type's classifier is still Void::class, until KT-15518 is fixed. + // TODO: support a special KClass instance for Nothing (KT-15518). + assertEquals(Void::class, typeOf>().arguments.single().type!!.classifier) + + assertNotEquals(typeOf>(), typeOf>()) + + return "OK" +} + +inline fun returnTypeOf(block: () -> Z) = + typeOf() + +// FILE: J.java + +public class J { + public static X platformType() { return null; } +} diff --git a/compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt b/compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt new file mode 100644 index 00000000000..44432fc61a0 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt @@ -0,0 +1,44 @@ +// !API_VERSION: 1.5 +// !USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi +// TARGET_BACKEND: JVM +// WITH_REFLECT +// FILE: box.kt + +package test + +import kotlin.reflect.KType +import kotlin.reflect.KTypeParameter +import kotlin.reflect.typeOf +import kotlin.test.assertEquals + +class C(v: V) + +fun nothingBound() = + (typeOf>().arguments.single().type!!.classifier as KTypeParameter).upperBounds.single() + +fun check(expected: String, actual: KType) { + assertEquals(expected, actual.toString()) +} + +fun box(): String { + check("test.C", typeOf>()) + check("test.C", typeOf>()) + check("kotlin.Nothing?", nothingBound()) + + check("test.C", returnTypeOf { C(J.platformType()) }) + + assertEquals(Void::class, typeOf>().arguments.single().type!!.classifier) + + assertEquals(typeOf>(), typeOf>()) + + return "OK" +} + +inline fun returnTypeOf(block: () -> Z) = + typeOf() + +// FILE: J.java + +public class J { + public static X platformType() { return null; } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 5a3c1c81c00..472ada91239 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -37467,6 +37467,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/reflection/typeOf/mutableCollections_before.kt"); } + @Test + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt"); + } + + @Test + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt"); + } + @Test @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { @@ -37540,6 +37552,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/mutableCollections_before.kt"); } + @Test + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt"); + } + + @Test + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt"); + } + @Test @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 6db0240ee3d..60f9648f936 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -37509,6 +37509,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/reflection/typeOf/mutableCollections_before.kt"); } + @Test + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt"); + } + + @Test + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt"); + } + @Test @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { @@ -37582,6 +37594,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/mutableCollections_before.kt"); } + @Test + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt"); + } + + @Test + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt"); + } + @Test @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 3bd66dbc8d3..dd49722c38f 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -29830,6 +29830,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/reflection/typeOf/mutableCollections_before.kt"); } + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_after.kt"); + } + + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/nothing_before.kt"); + } + @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { runTest("compiler/testData/codegen/box/reflection/typeOf/rawTypes_after.kt"); @@ -29900,6 +29910,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/mutableCollections_before.kt"); } + @TestMetadata("nothing_after.kt") + public void testNothing_after() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_after.kt"); + } + + @TestMetadata("nothing_before.kt") + public void testNothing_before() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/nothing_before.kt"); + } + @TestMetadata("rawTypes_after.kt") public void testRawTypes_after() throws Exception { runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/rawTypes_after.kt"); diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java index ec036d546d6..2e02308c7fe 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/ReflectionFactoryImpl.java @@ -157,6 +157,11 @@ public class ReflectionFactoryImpl extends ReflectionFactory { return TypeOfImplKt.createMutableCollectionKType(type); } + // @Override // JPS + public KType nothingType(KType type) { + return TypeOfImplKt.createNothingType(type); + } + // Misc public static void clearCaches() { diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/typeOfImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/typeOfImpl.kt index 674a47017ff..25e7738b69f 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/typeOfImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/typeOfImpl.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.types.KotlinTypeFactory import org.jetbrains.kotlin.types.SimpleType +import org.jetbrains.kotlin.types.typeUtil.builtIns import kotlin.reflect.KType internal fun createPlatformKType(lowerBound: KType, upperBound: KType): KType { @@ -39,3 +40,11 @@ private fun ClassDescriptor.readOnlyToMutable(): ClassDescriptor { ?: throw IllegalArgumentException("Not a readonly collection: $this") return builtIns.getBuiltInClassByFqName(fqName) } + +internal fun createNothingType(type: KType): KType { + val kotlinType = (type as KTypeImpl).type + require(kotlinType is SimpleType) { "Non-simple type cannot be a Nothing type: $type" } + return KTypeImpl( + KotlinTypeFactory.simpleType(kotlinType, constructor = kotlinType.builtIns.nothing.typeConstructor) + ) +} diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/Reflection.java b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/Reflection.java index 0a51bfc7ad5..fb308bbe800 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/Reflection.java +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/Reflection.java @@ -195,4 +195,9 @@ public class Reflection { public static KType mutableCollectionType(KType type) { return factory.mutableCollectionType(type); } + + @SinceKotlin(version = "1.6") + public static KType nothingType(KType type) { + return factory.nothingType(type); + } } diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ReflectionFactory.java b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ReflectionFactory.java index dc03986bf0a..b6c19fbdee2 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ReflectionFactory.java +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/ReflectionFactory.java @@ -97,18 +97,26 @@ public class ReflectionFactory { @SinceKotlin(version = "1.6") public KType platformType(KType lowerBound, KType upperBound) { return new TypeReference( - lowerBound.getClassifier(), lowerBound.getArguments(), lowerBound.isMarkedNullable(), - upperBound, - ((TypeReference) lowerBound).getMutableCollectionType$kotlin_stdlib() + lowerBound.getClassifier(), lowerBound.getArguments(), upperBound, + ((TypeReference) lowerBound).getFlags$kotlin_stdlib() ); } @SinceKotlin(version = "1.6") public KType mutableCollectionType(KType type) { + TypeReference typeRef = (TypeReference) type; return new TypeReference( - type.getClassifier(), type.getArguments(), type.isMarkedNullable(), - ((TypeReference) type).getPlatformTypeUpperBound$kotlin_stdlib(), - true + type.getClassifier(), type.getArguments(), typeRef.getPlatformTypeUpperBound$kotlin_stdlib(), + typeRef.getFlags$kotlin_stdlib() | TypeReference.IS_MUTABLE_COLLECTION_TYPE + ); + } + + @SinceKotlin(version = "1.6") + public KType nothingType(KType type) { + TypeReference typeRef = (TypeReference) type; + return new TypeReference( + type.getClassifier(), type.getArguments(), typeRef.getPlatformTypeUpperBound$kotlin_stdlib(), + typeRef.getFlags$kotlin_stdlib() | TypeReference.IS_NOTHING_TYPE ); } } diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/TypeReference.kt b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/TypeReference.kt index 53e954f6a40..f593b919b89 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/TypeReference.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/TypeReference.kt @@ -13,26 +13,28 @@ import kotlin.reflect.* public class TypeReference /* @SinceKotlin("1.6") constructor */( override val classifier: KClassifier, override val arguments: List, - override val isMarkedNullable: Boolean, - internal val platformTypeUpperBound: KType?, - internal val mutableCollectionType: Boolean, + /* @SinceKotlin("1.6") */ internal val platformTypeUpperBound: KType?, + /* @SinceKotlin("1.6") */ internal val flags: Int, ) : KType { constructor( classifier: KClassifier, arguments: List, isMarkedNullable: Boolean, - ) : this(classifier, arguments, isMarkedNullable, null, false) + ) : this(classifier, arguments, null, if (isMarkedNullable) IS_MARKED_NULLABLE else 0) override val annotations: List get() = emptyList() + override val isMarkedNullable: Boolean + get() = flags and IS_MARKED_NULLABLE != 0 + override fun equals(other: Any?): Boolean = other is TypeReference && - classifier == other.classifier && arguments == other.arguments && isMarkedNullable == other.isMarkedNullable && - platformTypeUpperBound == other.platformTypeUpperBound && mutableCollectionType == other.mutableCollectionType + classifier == other.classifier && arguments == other.arguments && platformTypeUpperBound == other.platformTypeUpperBound && + flags == other.flags override fun hashCode(): Int = - (classifier.hashCode() * 31 + arguments.hashCode()) * 31 + isMarkedNullable.hashCode() + (classifier.hashCode() * 31 + arguments.hashCode()) * 31 + flags.hashCode() override fun toString(): String = asString(false) + Reflection.REFLECTION_NOT_AVAILABLE @@ -41,6 +43,7 @@ public class TypeReference /* @SinceKotlin("1.6") constructor */( val javaClass = (classifier as? KClass<*>)?.java val klass = when { javaClass == null -> classifier.toString() + flags and IS_NOTHING_TYPE != 0 -> "kotlin.Nothing" javaClass.isArray -> javaClass.arrayClassName convertPrimitiveToWrapper && javaClass.isPrimitive -> (classifier as KClass<*>).javaObjectType.name else -> javaClass.name @@ -78,4 +81,11 @@ public class TypeReference /* @SinceKotlin("1.6") constructor */( KVariance.OUT -> "out $typeString" } } + + // @SinceKotlin("1.6") + internal companion object { + internal const val IS_MARKED_NULLABLE = 1 shl 0 + internal const val IS_MUTABLE_COLLECTION_TYPE = 1 shl 1 + internal const val IS_NOTHING_TYPE = 1 shl 2 + } } diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index b38f2ea9d9a..b5929de48eb 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -3991,6 +3991,7 @@ public class kotlin/jvm/internal/Reflection { public static fun mutableProperty0 (Lkotlin/jvm/internal/MutablePropertyReference0;)Lkotlin/reflect/KMutableProperty0; public static fun mutableProperty1 (Lkotlin/jvm/internal/MutablePropertyReference1;)Lkotlin/reflect/KMutableProperty1; public static fun mutableProperty2 (Lkotlin/jvm/internal/MutablePropertyReference2;)Lkotlin/reflect/KMutableProperty2; + public static fun nothingType (Lkotlin/reflect/KType;)Lkotlin/reflect/KType; public static fun nullableTypeOf (Ljava/lang/Class;)Lkotlin/reflect/KType; public static fun nullableTypeOf (Ljava/lang/Class;Lkotlin/reflect/KTypeProjection;)Lkotlin/reflect/KType; public static fun nullableTypeOf (Ljava/lang/Class;Lkotlin/reflect/KTypeProjection;Lkotlin/reflect/KTypeProjection;)Lkotlin/reflect/KType; @@ -4024,6 +4025,7 @@ public class kotlin/jvm/internal/ReflectionFactory { public fun mutableProperty0 (Lkotlin/jvm/internal/MutablePropertyReference0;)Lkotlin/reflect/KMutableProperty0; public fun mutableProperty1 (Lkotlin/jvm/internal/MutablePropertyReference1;)Lkotlin/reflect/KMutableProperty1; public fun mutableProperty2 (Lkotlin/jvm/internal/MutablePropertyReference2;)Lkotlin/reflect/KMutableProperty2; + public fun nothingType (Lkotlin/reflect/KType;)Lkotlin/reflect/KType; public fun platformType (Lkotlin/reflect/KType;Lkotlin/reflect/KType;)Lkotlin/reflect/KType; public fun property0 (Lkotlin/jvm/internal/PropertyReference0;)Lkotlin/reflect/KProperty0; public fun property1 (Lkotlin/jvm/internal/PropertyReference1;)Lkotlin/reflect/KProperty1; @@ -4123,19 +4125,26 @@ public final class kotlin/jvm/internal/TypeParameterReference$Companion { } public final class kotlin/jvm/internal/TypeReference : kotlin/reflect/KType { + public static final field Companion Lkotlin/jvm/internal/TypeReference$Companion; + public static final field IS_MARKED_NULLABLE I + public static final field IS_MUTABLE_COLLECTION_TYPE I + public static final field IS_NOTHING_TYPE I + public fun (Lkotlin/reflect/KClassifier;Ljava/util/List;Lkotlin/reflect/KType;I)V public fun (Lkotlin/reflect/KClassifier;Ljava/util/List;Z)V - public fun (Lkotlin/reflect/KClassifier;Ljava/util/List;ZLkotlin/reflect/KType;Z)V public fun equals (Ljava/lang/Object;)Z public fun getAnnotations ()Ljava/util/List; public fun getArguments ()Ljava/util/List; public fun getClassifier ()Lkotlin/reflect/KClassifier; - public final fun getMutableCollectionType$kotlin_stdlib ()Z + public final fun getFlags$kotlin_stdlib ()I public final fun getPlatformTypeUpperBound$kotlin_stdlib ()Lkotlin/reflect/KType; public fun hashCode ()I public fun isMarkedNullable ()Z public fun toString ()Ljava/lang/String; } +public final class kotlin/jvm/internal/TypeReference$Companion { +} + public abstract interface class kotlin/jvm/internal/markers/KMappedMarker { }