Support Void.TYPE as underlying Class object for KClass
#KT-20875 Fixed
This commit is contained in:
@@ -50,14 +50,15 @@ fun box(): String {
|
||||
check(Double::class.javaPrimitiveType, "double")
|
||||
check(Double::class, "double")
|
||||
|
||||
check(Void::class.javaPrimitiveType, "void")
|
||||
check(Void::class, "void")
|
||||
|
||||
checkNull(String::class.javaPrimitiveType)
|
||||
checkNull(String::class)
|
||||
|
||||
checkNull(Nothing::class.javaPrimitiveType)
|
||||
checkNull(Nothing::class)
|
||||
|
||||
checkNull(Void::class.javaPrimitiveType)
|
||||
checkNull(Void::class)
|
||||
// TODO: KT-15518
|
||||
check(Nothing::class.javaPrimitiveType, "void")
|
||||
check(Nothing::class, "void")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,9 +26,9 @@ fun box(): String {
|
||||
check<Float>("float")
|
||||
check<Long>("long")
|
||||
check<Double>("double")
|
||||
check<Void>("void")
|
||||
|
||||
checkNull<String>()
|
||||
checkNull<Void>()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(Void::class, Void.TYPE.kotlin)
|
||||
assertEquals(Void.TYPE.kotlin, Void::class)
|
||||
|
||||
assertEquals(Void.TYPE, Void::class.javaPrimitiveType)
|
||||
assertEquals(Void::class.java, Void::class.javaObjectType)
|
||||
assertEquals(Void.TYPE, Void.TYPE.kotlin.javaPrimitiveType)
|
||||
assertEquals(Void::class.java, Void.TYPE.kotlin.javaObjectType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(Void::class, Void.TYPE.kotlin)
|
||||
assertEquals(Void.TYPE.kotlin, Void::class)
|
||||
|
||||
assertEquals(Void.TYPE, Void::class.javaPrimitiveType)
|
||||
assertEquals(Void::class.java, Void::class.javaObjectType)
|
||||
assertEquals(Void.TYPE, Void.TYPE.kotlin.javaPrimitiveType)
|
||||
assertEquals(Void::class.java, Void.TYPE.kotlin.javaObjectType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -16249,6 +16249,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/javaVoid.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmName.kt")
|
||||
public void testJvmName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/jvmName.kt");
|
||||
@@ -17275,6 +17281,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/javaVoid.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primitiveJavaClass.kt")
|
||||
public void testPrimitiveJavaClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/primitiveJavaClass.kt");
|
||||
|
||||
@@ -16249,6 +16249,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/javaVoid.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmName.kt")
|
||||
public void testJvmName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/jvmName.kt");
|
||||
@@ -17275,6 +17281,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/javaVoid.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primitiveJavaClass.kt")
|
||||
public void testPrimitiveJavaClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/primitiveJavaClass.kt");
|
||||
|
||||
@@ -16249,6 +16249,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/javaVoid.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmName.kt")
|
||||
public void testJvmName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/jvmName.kt");
|
||||
@@ -17275,6 +17281,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/javaVoid.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primitiveJavaClass.kt")
|
||||
public void testPrimitiveJavaClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/primitiveJavaClass.kt");
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.NameUtils
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
@@ -156,6 +157,8 @@ private val Method.signature: String
|
||||
returnType.desc
|
||||
|
||||
internal object RuntimeTypeMapper {
|
||||
private val JAVA_LANG_VOID = ClassId.topLevel(FqName("java.lang.Void"))
|
||||
|
||||
fun mapSignature(possiblySubstitutedFunction: FunctionDescriptor): JvmFunctionSignature {
|
||||
// Fake overrides don't have a source element, so we need to take a declaration.
|
||||
// TODO: support the case when a fake override overrides several declarations with different signatures
|
||||
@@ -263,6 +266,8 @@ internal object RuntimeTypeMapper {
|
||||
return ClassId.topLevel(KotlinBuiltIns.FQ_NAMES.array.toSafe())
|
||||
}
|
||||
|
||||
if (klass == Void.TYPE) return JAVA_LANG_VOID
|
||||
|
||||
klass.primitiveType?.let {
|
||||
return ClassId(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME, it.typeName)
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ public val <T : Any> KClass<T>.javaPrimitiveType: Class<T>?
|
||||
"java.lang.Float" -> Float::class.java
|
||||
"java.lang.Long" -> Long::class.java
|
||||
"java.lang.Double" -> Double::class.java
|
||||
"java.lang.Void" -> Void.TYPE
|
||||
else -> null
|
||||
} as Class<T>?
|
||||
}
|
||||
@@ -77,6 +78,7 @@ public val <T : Any> KClass<T>.javaObjectType: Class<T>
|
||||
"float" -> JavaLangFloat::class.java
|
||||
"long" -> JavaLangLong::class.java
|
||||
"double" -> JavaLangDouble::class.java
|
||||
"void" -> Void::class.java
|
||||
else -> thisJClass
|
||||
} as Class<T>
|
||||
}
|
||||
|
||||
+24
@@ -18193,6 +18193,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/javaVoid.kt");
|
||||
try {
|
||||
doTest(fileName);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return;
|
||||
}
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmName.kt")
|
||||
public void testJvmName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/classes/jvmName.kt");
|
||||
@@ -20065,6 +20077,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("javaVoid.kt")
|
||||
public void testJavaVoid() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/javaVoid.kt");
|
||||
try {
|
||||
doTest(fileName);
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
return;
|
||||
}
|
||||
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||
}
|
||||
|
||||
@TestMetadata("primitiveJavaClass.kt")
|
||||
public void testPrimitiveJavaClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/noReflectAtRuntime/primitiveJavaClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user