FIR2IR: Fix inheritance case from built-in interface with default methods

This commit is contained in:
Denis.Zharkov
2021-03-31 17:21:51 +03:00
parent e5ea7f5b4e
commit d685e2aac7
7 changed files with 51 additions and 0 deletions
@@ -447,6 +447,12 @@ class Fir2IrDeclarationStorage(
isLambda -> IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
function.symbol.callableId.isKFunctionInvoke() -> IrDeclarationOrigin.FAKE_OVERRIDE
simpleFunction?.isStatic == true && simpleFunction.name in ENUM_SYNTHETIC_NAMES -> IrDeclarationOrigin.ENUM_CLASS_SPECIAL_MEMBER
// Kotlin built-in class and Java originated method (Collection.forEach, etc.)
// It's necessary to understand that such methods do not belong to DefaultImpls but actually generated as default
// See org.jetbrains.kotlin.backend.jvm.lower.InheritedDefaultMethodsOnClassesLoweringKt.isDefinitelyNotDefaultImplsMethod
(irParent as? IrClass)?.origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB &&
function.origin == FirDeclarationOrigin.Enhancement -> IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
else -> origin
}
classifierStorage.preCacheTypeParameters(function)
@@ -22137,6 +22137,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/jvm8/defaults/bridgeWithJava.kt");
}
@Test
@TestMetadata("builtInsInherited.kt")
public void testBuiltInsInherited() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt");
}
@Test
@TestMetadata("callableReference.kt")
public void testCallableReference() throws Exception {
@@ -0,0 +1,16 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// FULL_JDK
// WITH_RUNTIME
import java.util.function.Consumer
class A : Iterable<String> {
override fun iterator(): Iterator<String> = listOf("OK").iterator()
}
fun box(): String {
var res = ""
A().forEach(Consumer { res += it })
return res
}
@@ -22119,6 +22119,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/jvm8/defaults/bridgeWithJava.kt");
}
@Test
@TestMetadata("builtInsInherited.kt")
public void testBuiltInsInherited() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt");
}
@Test
@TestMetadata("callableReference.kt")
public void testCallableReference() throws Exception {
@@ -22137,6 +22137,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvm8/defaults/bridgeWithJava.kt");
}
@Test
@TestMetadata("builtInsInherited.kt")
public void testBuiltInsInherited() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt");
}
@Test
@TestMetadata("callableReference.kt")
public void testCallableReference() throws Exception {
@@ -18577,6 +18577,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvm8/defaults/bridgeWithJava.kt");
}
@TestMetadata("builtInsInherited.kt")
public void testBuiltInsInherited() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt");
}
@TestMetadata("callableReference.kt")
public void testCallableReference() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/callableReference.kt");
@@ -22148,6 +22148,12 @@ public class VisualizerBlackBoxTestGenerated extends AbstractVisualizerBlackBoxT
runTest("compiler/testData/codegen/box/jvm8/defaults/bridgeWithJava.kt");
}
@Test
@TestMetadata("builtInsInherited.kt")
public void testBuiltInsInherited() throws Exception {
runTest("compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt");
}
@Test
@TestMetadata("callableReference.kt")
public void testCallableReference() throws Exception {