JVM IR: do not generate invokeinterface hashCode if smart cast is present
#KT-45008 Fixed
This commit is contained in:
+6
@@ -3141,6 +3141,12 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest {
|
|||||||
public void testInterfaceHashCode() throws Exception {
|
public void testInterfaceHashCode() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCode.kt");
|
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
|
@Nested
|
||||||
|
|||||||
+1
-1
@@ -233,7 +233,7 @@ private class InterfaceObjectCallsLowering(val context: JvmBackendContext) : IrE
|
|||||||
if (expression.superQualifierSymbol != null && !expression.isSuperToAny())
|
if (expression.superQualifierSymbol != null && !expression.isSuperToAny())
|
||||||
return super.visitCall(expression)
|
return super.visitCall(expression)
|
||||||
val callee = expression.symbol.owner
|
val callee = expression.symbol.owner
|
||||||
if (!callee.hasInterfaceParent())
|
if (!callee.hasInterfaceParent() && expression.dispatchReceiver?.run { type.erasedUpperBound.isJvmInterface } != true)
|
||||||
return super.visitCall(expression)
|
return super.visitCall(expression)
|
||||||
val resolved = callee.resolveFakeOverride()
|
val resolved = callee.resolveFakeOverride()
|
||||||
if (resolved?.isMethodOfAny() != true)
|
if (resolved?.isMethodOfAny() != true)
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
interface I
|
||||||
|
|
||||||
|
class A : I {
|
||||||
|
fun f1(other: Any?): Int =
|
||||||
|
if (other is I) other.hashCode() else 0
|
||||||
|
|
||||||
|
inline fun <reified T : I> f2(other: Any): Int =
|
||||||
|
if (other is T) other.hashCode() else 0
|
||||||
|
|
||||||
|
fun f3() {
|
||||||
|
f2<A>(A())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3 INVOKEVIRTUAL java/lang/Object.hashCode \(\)I
|
||||||
|
// 0 INVOKEINTERFACE
|
||||||
+6
@@ -3009,6 +3009,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
public void testInterfaceHashCode() throws Exception {
|
public void testInterfaceHashCode() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCode.kt");
|
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
|
@Nested
|
||||||
|
|||||||
+6
@@ -3141,6 +3141,12 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
|||||||
public void testInterfaceHashCode() throws Exception {
|
public void testInterfaceHashCode() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/hashCode/interfaceHashCode.kt");
|
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
|
@Nested
|
||||||
|
|||||||
Reference in New Issue
Block a user