Fix error with interpreting name of java property

This commit is contained in:
Ivan Kylchik
2022-05-23 15:54:26 +03:00
committed by teamcity
parent af6f17c243
commit 07ba9be2e0
6 changed files with 29 additions and 6 deletions
@@ -604,7 +604,11 @@ class IrInterpreter(internal val environment: IrInterpreterEnvironment, internal
fun List<IrTypeParameter>.addToFields() {
(0 until propertyReference.typeArgumentsCount).forEach { index ->
val kTypeState = KTypeState(propertyReference.getTypeArgument(index)!!, environment.kTypeClass.owner)
// We need nullable check for java case in FIR
// For some reason it is possible that typeArgumentsCount > 0, but all args are null
// TODO report as error after fix KT-52480
val typeArgument = propertyReference.getTypeArgument(index) ?: return@forEach
val kTypeState = KTypeState(typeArgument, environment.kTypeClass.owner)
propertyState.setField(this[index].symbol, kTypeState)
}
}
@@ -20,7 +20,7 @@ internal open class KProperty0Proxy(
state: KPropertyState, callInterceptor: CallInterceptor
) : AbstractKPropertyProxy(state, callInterceptor), KProperty0<Any?> {
override val getter: KProperty0.Getter<Any?>
get() = object : Getter(state.property.getter!!), KProperty0.Getter<Any?> {
get() = object : Getter(state.property.getter!!), KProperty0.Getter<Any?> { // TODO avoid !!; getter will be null in case of java property
override fun invoke(): Any? = call()
override fun call(vararg args: Any?): Any? {
@@ -54,8 +54,8 @@ internal open class KProperty0Proxy(
internal class KMutableProperty0Proxy(
state: KPropertyState, callInterceptor: CallInterceptor
) : KProperty0Proxy(state, callInterceptor), KMutableProperty0<Any?> {
override val setter: KMutableProperty0.Setter<Any?> =
object : Setter(state.property.setter!!), KMutableProperty0.Setter<Any?> {
override val setter: KMutableProperty0.Setter<Any?>
get() = object : Setter(state.property.setter!!), KMutableProperty0.Setter<Any?> {
override fun invoke(p1: Any?) = call(p1)
override fun call(vararg args: Any?) {
@@ -54,8 +54,8 @@ internal open class KProperty1Proxy(
internal class KMutableProperty1Proxy(
state: KPropertyState, callInterceptor: CallInterceptor
) : KProperty1Proxy(state, callInterceptor), KMutableProperty1<Any?, Any?> {
override val setter: KMutableProperty1.Setter<Any?, Any?> =
object : Setter(state.property.setter!!), KMutableProperty1.Setter<Any?, Any?> {
override val setter: KMutableProperty1.Setter<Any?, Any?>
get() = object : Setter(state.property.setter!!), KMutableProperty1.Setter<Any?, Any?> {
override fun invoke(p1: Any?, p2: Any?) = call(p1, p2)
override fun call(vararg args: Any?) {
@@ -0,0 +1,7 @@
// FILE: Main.kt
const val name = <!EVALUATED: `SOME_PROPERTY`!>ClassWithProperty::SOME_PROPERTY.name<!>
// FILE: ClassWithProperty.java
public class ClassWithProperty {
public boolean SOME_PROPERTY = false;
}
@@ -706,6 +706,12 @@ public class IrInterpreterAfterFir2IrTestGenerated extends AbstractIrInterpreter
runTest("compiler/testData/ir/interpreter/reference/getClass.kt");
}
@Test
@TestMetadata("javaPropertyReference.kt")
public void testJavaPropertyReference() throws Exception {
runTest("compiler/testData/ir/interpreter/reference/javaPropertyReference.kt");
}
@Test
@TestMetadata("propertyReference.kt")
public void testPropertyReference() throws Exception {
@@ -706,6 +706,12 @@ public class IrInterpreterAfterPsi2IrTestGenerated extends AbstractIrInterpreter
runTest("compiler/testData/ir/interpreter/reference/getClass.kt");
}
@Test
@TestMetadata("javaPropertyReference.kt")
public void testJavaPropertyReference() throws Exception {
runTest("compiler/testData/ir/interpreter/reference/javaPropertyReference.kt");
}
@Test
@TestMetadata("propertyReference.kt")
public void testPropertyReference() throws Exception {