diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 03947b7aa78..7097a680ef9 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -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) diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 51ce0e95823..3e63b397035 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt b/compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt new file mode 100644 index 00000000000..ea4f79258bb --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/builtInsInherited.kt @@ -0,0 +1,16 @@ +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// FULL_JDK +// WITH_RUNTIME +import java.util.function.Consumer + +class A : Iterable { + override fun iterator(): Iterator = listOf("OK").iterator() +} + +fun box(): String { + var res = "" + A().forEach(Consumer { res += it }) + + return res +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 84c343133eb..5ab09f1239f 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 79e8c0b5682..26fbf57f29b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 5a1d5e4bba3..5dcf7977240 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/VisualizerBlackBoxTestGenerated.java b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/VisualizerBlackBoxTestGenerated.java index 10bad5422c8..d9efa92dfb7 100644 --- a/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/VisualizerBlackBoxTestGenerated.java +++ b/compiler/visualizer/tests-gen/org/jetbrains/kotlin/visualizer/VisualizerBlackBoxTestGenerated.java @@ -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 {