diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java index e7d11e266c3..42193513368 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBytecodeTextTestGenerated.java @@ -3141,6 +3141,12 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { public void testInterfaceHashCode() throws Exception { runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCode.kt"); } + + @Test + @TestMetadata("interfaceHashCodeWithSmartCast.kt") + public void testInterfaceHashCodeWithSmartCast() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCodeWithSmartCast.kt"); + } } @Nested diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt index 4c286cafaee..0c934061a5d 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt @@ -233,7 +233,7 @@ private class InterfaceObjectCallsLowering(val context: JvmBackendContext) : IrE if (expression.superQualifierSymbol != null && !expression.isSuperToAny()) return super.visitCall(expression) val callee = expression.symbol.owner - if (!callee.hasInterfaceParent()) + if (!callee.hasInterfaceParent() && expression.dispatchReceiver?.run { type.erasedUpperBound.isJvmInterface } != true) return super.visitCall(expression) val resolved = callee.resolveFakeOverride() if (resolved?.isMethodOfAny() != true) diff --git a/compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCodeWithSmartCast.kt b/compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCodeWithSmartCast.kt new file mode 100644 index 00000000000..1e3ef0a82a2 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCodeWithSmartCast.kt @@ -0,0 +1,16 @@ +interface I + +class A : I { + fun f1(other: Any?): Int = + if (other is I) other.hashCode() else 0 + + inline fun f2(other: Any): Int = + if (other is T) other.hashCode() else 0 + + fun f3() { + f2(A()) + } +} + +// 3 INVOKEVIRTUAL java/lang/Object.hashCode \(\)I +// 0 INVOKEINTERFACE diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java index 2953fa9dad3..f2262ddcc0a 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeTextTestGenerated.java @@ -3009,6 +3009,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { public void testInterfaceHashCode() throws Exception { runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCode.kt"); } + + @Test + @TestMetadata("interfaceHashCodeWithSmartCast.kt") + public void testInterfaceHashCodeWithSmartCast() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCodeWithSmartCast.kt"); + } } @Nested diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java index 67908bf703c..2333d6d7779 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeTextTestGenerated.java @@ -3141,6 +3141,12 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { public void testInterfaceHashCode() throws Exception { runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCode.kt"); } + + @Test + @TestMetadata("interfaceHashCodeWithSmartCast.kt") + public void testInterfaceHashCodeWithSmartCast() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCodeWithSmartCast.kt"); + } } @Nested