Fix assertion caused by wrong equality of DescriptorBasedFunctionHandleForJvm
In case of the same class defined in different modules they contain different descriptors instances in their scope that might lead to failing assertion in findConcreteSuperDeclaration because there are overridden from different modules It might happen even in the compiler because of different built-in modules defined for sources-module and for dependencies' one ^KT-29320 Fixed
This commit is contained in:
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.codegen
|
||||
import org.jetbrains.kotlin.backend.common.bridges.*
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmDefaultAnnotation
|
||||
@@ -31,13 +32,28 @@ class DescriptorBasedFunctionHandleForJvm(
|
||||
override val mayBeUsedAsSuperImplementation: Boolean =
|
||||
super.mayBeUsedAsSuperImplementation || descriptor.isJvmDefaultOrPlatformDependent()
|
||||
|
||||
private val asmMethod by lazy(LazyThreadSafetyMode.NONE) {
|
||||
state.typeMapper.mapAsmMethod(descriptor)
|
||||
}
|
||||
|
||||
override val isDeclaration: Boolean =
|
||||
descriptor.kind.isReal || needToGenerateDelegationToDefaultImpls(descriptor)
|
||||
|
||||
override val mightBeIncorrectCode: Boolean
|
||||
get() = state.classBuilderMode.mightBeIncorrectCode
|
||||
|
||||
override fun hashCode(): Int = descriptor.containerEntityForEqualityAndHashCode().hashCode() + 31 * asmMethod.hashCode()
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is DescriptorBasedFunctionHandleForJvm) return false
|
||||
|
||||
return asmMethod == other.asmMethod &&
|
||||
descriptor.containerEntityForEqualityAndHashCode() == other.descriptor.containerEntityForEqualityAndHashCode()
|
||||
}
|
||||
}
|
||||
|
||||
private fun FunctionDescriptor.containerEntityForEqualityAndHashCode(): Any =
|
||||
(containingDeclaration as? ClassDescriptor)?.typeConstructor ?: containingDeclaration
|
||||
|
||||
private fun CallableMemberDescriptor.isJvmDefaultOrPlatformDependent() =
|
||||
hasJvmDefaultAnnotation() || hasPlatformDependentAnnotation()
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
// FULL_JDK
|
||||
|
||||
import java.util.*
|
||||
|
||||
private class IntervalTreeMap : TreeMap<String, String>()
|
||||
|
||||
fun box(): String {
|
||||
val intervalTreeMap = IntervalTreeMap()
|
||||
intervalTreeMap.put("123", "356")
|
||||
|
||||
if (!intervalTreeMap.remove("123", "356")) return "fail 1"
|
||||
return intervalTreeMap.getOrDefault("123", "OK")
|
||||
}
|
||||
+5
@@ -13899,6 +13899,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/jvm8/simpleProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("treeMapBridge.kt")
|
||||
public void testTreeMapBridge() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvm8/treeMapBridge.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+5
@@ -13899,6 +13899,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/jvm8/simpleProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("treeMapBridge.kt")
|
||||
public void testTreeMapBridge() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvm8/treeMapBridge.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+5
@@ -13904,6 +13904,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/jvm8/simpleProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("treeMapBridge.kt")
|
||||
public void testTreeMapBridge() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/jvm8/treeMapBridge.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8/defaults")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user