Exclude builtins members mapped to java default methods from delegation
This commit is contained in:
@@ -16,20 +16,29 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
||||
import org.jetbrains.kotlin.serialization.deserialization.PLATFORM_DEPENDENT_ANNOTATION_FQ_NAME
|
||||
|
||||
object JvmDelegationFilter : DelegationFilter {
|
||||
|
||||
override fun filter(interfaceMember: CallableMemberDescriptor): Boolean {
|
||||
//We always have only one implementation otherwise it's an error in kotlin and java
|
||||
return !isJavaDefaultMethod(DescriptorUtils.unwrapFakeOverride(interfaceMember))
|
||||
val realMember = DescriptorUtils.unwrapFakeOverride(interfaceMember)
|
||||
return !isJavaDefaultMethod(realMember) && !isBuiltInMemberMappedToJavaDefault(realMember)
|
||||
}
|
||||
|
||||
private fun isJavaDefaultMethod(interfaceMember: CallableMemberDescriptor): Boolean {
|
||||
return interfaceMember is JavaMethodDescriptor && interfaceMember.modality != Modality.ABSTRACT
|
||||
}
|
||||
|
||||
private fun isBuiltInMemberMappedToJavaDefault(interfaceMember: CallableMemberDescriptor): Boolean {
|
||||
return interfaceMember.modality != Modality.ABSTRACT &&
|
||||
KotlinBuiltIns.isBuiltIn(interfaceMember) &&
|
||||
interfaceMember.annotations.hasAnnotation(PLATFORM_DEPENDENT_ANNOTATION_FQ_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// FULL_JDK
|
||||
|
||||
class MapWithBadDefaults : HashMap<String, String>() {
|
||||
override fun getOrDefault(key: String, defaultValue: String): String {
|
||||
throw RuntimeException("Shouldn't be executed")
|
||||
}
|
||||
|
||||
override fun remove(key: String, value: String): Boolean {
|
||||
throw RuntimeException("Shouldn't be executed")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Test(map: MutableMap<String, String>) : MutableMap<String, String> by map
|
||||
|
||||
fun box(): String {
|
||||
val test = Test(MapWithBadDefaults())
|
||||
test.put("O", "K")
|
||||
if (!test.containsKey("O")) return "fail 1: can't find value for key 'O'"
|
||||
if (!test.remove("O", "K")) return "fail 2: entry wasn't removed"
|
||||
|
||||
return test.getOrDefault("absent", "OK")
|
||||
}
|
||||
+6
@@ -140,6 +140,12 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("delegationToMap.kt")
|
||||
public void testDelegationToMap() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/delegationBy/delegationToMap.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("diamond.kt")
|
||||
public void testDiamond() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/delegationBy/diamond.kt");
|
||||
|
||||
Reference in New Issue
Block a user