JVM_IR indy-SAM conversions: tests for function references equality
(SAM conversion using LambdaMetafactory is not used for function refs). KT-44278 KT-26060 KT-42621
This commit is contained in:
+12
@@ -18397,6 +18397,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/sam"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boundFunctionReferenceEquality.kt")
|
||||
public void testBoundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/boundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boundReference.kt")
|
||||
public void testBoundReference() throws Exception {
|
||||
@@ -18505,6 +18511,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unboundFunctionReferenceEquality.kt")
|
||||
public void testUnboundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/unboundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/invokedynamic/sam/inline")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// WITH_RUNTIME
|
||||
// FILE: boundAdaptedFunctionReference.kt
|
||||
fun checkEqual(x: Any, y: Any) {
|
||||
if (x != y || y != x) throw AssertionError("$x and $y should be equal")
|
||||
if (x.hashCode() != y.hashCode()) throw AssertionError("$x and $y should have the same hash code")
|
||||
}
|
||||
|
||||
fun checkNotEqual(x: Any, y: Any) {
|
||||
if (x == y || y == x) throw AssertionError("$x and $y should NOT be equal")
|
||||
}
|
||||
|
||||
fun interface FunInterface {
|
||||
fun invoke()
|
||||
}
|
||||
|
||||
private fun id(f: FunInterface): Any = f
|
||||
|
||||
class C {
|
||||
fun target1() {}
|
||||
fun target2() {}
|
||||
|
||||
fun adapted1(s: String? = null): String = s!!
|
||||
fun adapted2(vararg s: String): String = s[0]
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c0 = C()
|
||||
|
||||
checkEqual(id(c0::target1), id(c0::target1))
|
||||
checkEqual(id(c0::target1), target1FromOtherFile(c0))
|
||||
|
||||
checkNotEqual(id(c0::target1), id(c0::target2))
|
||||
|
||||
checkEqual(id(c0::adapted1), id(c0::adapted1))
|
||||
checkEqual(id(c0::adapted1), adapted1FromOtherFile(c0))
|
||||
checkEqual(id(c0::adapted2), id(c0::adapted2))
|
||||
checkEqual(id(c0::adapted2), adapted2FromOtherFile(c0))
|
||||
checkNotEqual(id(c0::adapted1), id(c0::adapted2))
|
||||
|
||||
val c1 = C()
|
||||
checkNotEqual(id(c0::target1), id(c1::target1))
|
||||
checkNotEqual(id(c0::target1), id(c1::target2))
|
||||
checkNotEqual(id(c0::adapted1), id(c1::adapted1))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: fromOtherFile.kt
|
||||
|
||||
private fun id(f: FunInterface): Any = f
|
||||
|
||||
fun target1FromOtherFile(c0: C): Any = id(c0::target1)
|
||||
fun adapted1FromOtherFile(c0: C): Any = id(c0::adapted1)
|
||||
fun adapted2FromOtherFile(c0: C): Any = id(c0::adapted2)
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// WITH_RUNTIME
|
||||
// FILE: unboundAdaptedFunctionReference.kt
|
||||
fun checkEqual(x: Any, y: Any) {
|
||||
if (x != y || y != x) throw AssertionError("$x and $y should be equal")
|
||||
if (x.hashCode() != y.hashCode()) throw AssertionError("$x and $y should have the same hash code")
|
||||
}
|
||||
|
||||
fun checkNotEqual(x: Any, y: Any) {
|
||||
if (x == y || y == x) throw AssertionError("$x and $y should NOT be equal")
|
||||
}
|
||||
|
||||
fun interface FunInterface {
|
||||
fun invoke()
|
||||
}
|
||||
|
||||
private fun id(f: FunInterface): Any = f
|
||||
|
||||
fun target1() {}
|
||||
fun target2() {}
|
||||
|
||||
fun adapted1(s: String? = null): String = s!!
|
||||
fun adapted2(vararg s: String): String = s[0]
|
||||
|
||||
fun box(): String {
|
||||
checkEqual(id(::target1), id(::target1))
|
||||
checkEqual(id(::target1), target1FromOtherFile())
|
||||
|
||||
checkNotEqual(id(::target1), id(::target2))
|
||||
|
||||
checkEqual(id(::adapted1), id(::adapted1))
|
||||
checkEqual(id(::adapted1), adapted1FromOtherFile())
|
||||
checkEqual(id(::adapted2), id(::adapted2))
|
||||
checkEqual(id(::adapted2), adapted2FromOtherFile())
|
||||
checkNotEqual(id(::adapted1), id(::adapted2))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: fromOtherFile.kt
|
||||
|
||||
private fun id(f: FunInterface): Any = f
|
||||
|
||||
fun target1FromOtherFile(): Any = id(::target1)
|
||||
fun adapted1FromOtherFile(): Any = id(::adapted1)
|
||||
fun adapted2FromOtherFile(): Any = id(::adapted2)
|
||||
+12
@@ -18397,6 +18397,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/sam"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boundFunctionReferenceEquality.kt")
|
||||
public void testBoundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/boundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boundReference.kt")
|
||||
public void testBoundReference() throws Exception {
|
||||
@@ -18505,6 +18511,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unboundFunctionReferenceEquality.kt")
|
||||
public void testUnboundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/unboundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/invokedynamic/sam/inline")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+12
@@ -18397,6 +18397,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/sam"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boundFunctionReferenceEquality.kt")
|
||||
public void testBoundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/boundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("boundReference.kt")
|
||||
public void testBoundReference() throws Exception {
|
||||
@@ -18505,6 +18511,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unboundFunctionReferenceEquality.kt")
|
||||
public void testUnboundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/unboundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/invokedynamic/sam/inline")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+10
@@ -16133,6 +16133,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/sam"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("boundFunctionReferenceEquality.kt")
|
||||
public void testBoundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/boundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("boundReference.kt")
|
||||
public void testBoundReference() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/boundReference.kt");
|
||||
@@ -16223,6 +16228,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unboundFunctionReferenceEquality.kt")
|
||||
public void testUnboundFunctionReferenceEquality() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/unboundFunctionReferenceEquality.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/invokedynamic/sam/inline")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user