Return kotlin ctor mapped to a java ctor even if java ctor is synthetic
This allows working with constructors with inline class parameters using Kotlin reflection, as described in https://youtrack.jetbrains.com/issue/KT-27429#focus=streamItem-27-3161148-0-0 #KT-27913 #KT-27429
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
import kotlin.reflect.jvm.javaConstructor
|
||||
import kotlin.reflect.jvm.kotlinFunction
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline class Z(val x: Int)
|
||||
|
||||
class Test(val x: Z)
|
||||
|
||||
fun box(): String {
|
||||
val kctor1 = Test::class.primaryConstructor ?: throw AssertionError("No primary constructor")
|
||||
val jctor1 = kctor1.javaConstructor ?: throw AssertionError("No javaConstructor for $kctor1")
|
||||
val kctor2 = jctor1.kotlinFunction ?: throw AssertionError("No kotlinFunction for $jctor1")
|
||||
|
||||
assertEquals(kctor1, kctor2)
|
||||
assertEquals("[x]", kctor2.parameters.map { it.name }.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -20200,6 +20200,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorWithInlineClassParameters.kt")
|
||||
public void testConstructorWithInlineClassParameters() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructorWithInlineClassParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionProperty.kt")
|
||||
public void testExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/extensionProperty.kt");
|
||||
|
||||
+5
@@ -20200,6 +20200,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorWithInlineClassParameters.kt")
|
||||
public void testConstructorWithInlineClassParameters() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructorWithInlineClassParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionProperty.kt")
|
||||
public void testExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/extensionProperty.kt");
|
||||
|
||||
+5
@@ -20205,6 +20205,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorWithInlineClassParameters.kt")
|
||||
public void testConstructorWithInlineClassParameters() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructorWithInlineClassParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionProperty.kt")
|
||||
public void testExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/extensionProperty.kt");
|
||||
|
||||
@@ -144,7 +144,5 @@ val Method.kotlinFunction: KFunction<*>?
|
||||
*/
|
||||
val <T : Any> Constructor<T>.kotlinFunction: KFunction<T>?
|
||||
get() {
|
||||
if (isSynthetic) return null
|
||||
|
||||
return declaringClass.kotlin.constructors.firstOrNull { it.javaConstructor == this }
|
||||
}
|
||||
|
||||
+5
@@ -17665,6 +17665,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorWithInlineClassParameters.kt")
|
||||
public void testConstructorWithInlineClassParameters() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructorWithInlineClassParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionProperty.kt")
|
||||
public void testExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/extensionProperty.kt");
|
||||
|
||||
+5
@@ -18720,6 +18720,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorWithInlineClassParameters.kt")
|
||||
public void testConstructorWithInlineClassParameters() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/constructorWithInlineClassParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionProperty.kt")
|
||||
public void testExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/mapping/extensionProperty.kt");
|
||||
|
||||
Reference in New Issue
Block a user