[Reflection] Use reference equality to determine that a callable reference is bound
It helps to avoid problems when receiver object implements structural equals violating the equality contract #KT-60709
This commit is contained in:
committed by
Space Team
parent
64f90f685d
commit
291d52820c
+6
@@ -45162,6 +45162,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
|||||||
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt60709.kt")
|
||||||
|
public void testKt60709() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt60709.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt61304.kt")
|
@TestMetadata("kt61304.kt")
|
||||||
public void testKt61304() throws Exception {
|
public void testKt61304() throws Exception {
|
||||||
|
|||||||
+6
@@ -45162,6 +45162,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
|||||||
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt60709.kt")
|
||||||
|
public void testKt60709() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt60709.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt61304.kt")
|
@TestMetadata("kt61304.kt")
|
||||||
public void testKt61304() throws Exception {
|
public void testKt61304() throws Exception {
|
||||||
|
|||||||
+6
@@ -45162,6 +45162,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
|||||||
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt60709.kt")
|
||||||
|
public void testKt60709() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt60709.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt61304.kt")
|
@TestMetadata("kt61304.kt")
|
||||||
public void testKt61304() throws Exception {
|
public void testKt61304() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
class Eq {
|
||||||
|
override fun equals(other: Any?): Boolean = true
|
||||||
|
override fun toString(): String = "1"
|
||||||
|
val x: String get() = "2"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
require(Eq()::toString.callBy(mapOf()) == "1")
|
||||||
|
require(Eq()::x.callBy(mapOf()) == "2")
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -42390,6 +42390,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt60709.kt")
|
||||||
|
public void testKt60709() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt60709.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt61304.kt")
|
@TestMetadata("kt61304.kt")
|
||||||
public void testKt61304() throws Exception {
|
public void testKt61304() throws Exception {
|
||||||
|
|||||||
+6
@@ -45162,6 +45162,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt60709.kt")
|
||||||
|
public void testKt60709() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt60709.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt61304.kt")
|
@TestMetadata("kt61304.kt")
|
||||||
public void testKt61304() throws Exception {
|
public void testKt61304() throws Exception {
|
||||||
|
|||||||
+6
@@ -45162,6 +45162,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
|||||||
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt60709.kt")
|
||||||
|
public void testKt60709() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt60709.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt61304.kt")
|
@TestMetadata("kt61304.kt")
|
||||||
public void testKt61304() throws Exception {
|
public void testKt61304() throws Exception {
|
||||||
|
|||||||
+5
@@ -35884,6 +35884,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/jvmStaticInObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt60709.kt")
|
||||||
|
public void testKt60709() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt60709.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt61304.kt")
|
@TestMetadata("kt61304.kt")
|
||||||
public void testKt61304() throws Exception {
|
public void testKt61304() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/reflection/callBy/kt61304.kt");
|
runTest("compiler/testData/codegen/box/reflection/callBy/kt61304.kt");
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ internal class KFunctionImpl private constructor(
|
|||||||
descriptor
|
descriptor
|
||||||
)
|
)
|
||||||
|
|
||||||
override val isBound: Boolean get() = rawBoundReceiver != CallableReference.NO_RECEIVER
|
override val isBound: Boolean get() = rawBoundReceiver !== CallableReference.NO_RECEIVER
|
||||||
|
|
||||||
override val descriptor: FunctionDescriptor by ReflectProperties.lazySoft(descriptorInitialValue) {
|
override val descriptor: FunctionDescriptor by ReflectProperties.lazySoft(descriptorInitialValue) {
|
||||||
container.findFunctionDescriptor(name, signature)
|
container.findFunctionDescriptor(name, signature)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ internal abstract class KPropertyImpl<out V> private constructor(
|
|||||||
val boundReceiver
|
val boundReceiver
|
||||||
get() = rawBoundReceiver.coerceToExpectedReceiverType(descriptor)
|
get() = rawBoundReceiver.coerceToExpectedReceiverType(descriptor)
|
||||||
|
|
||||||
override val isBound: Boolean get() = rawBoundReceiver != CallableReference.NO_RECEIVER
|
override val isBound: Boolean get() = rawBoundReceiver !== CallableReference.NO_RECEIVER
|
||||||
|
|
||||||
private val _javaField = lazy(PUBLICATION) {
|
private val _javaField = lazy(PUBLICATION) {
|
||||||
when (val jvmSignature = RuntimeTypeMapper.mapPropertySignature(descriptor)) {
|
when (val jvmSignature = RuntimeTypeMapper.mapPropertySignature(descriptor)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user