Change behavior of equals/hashCode on adapted function references

Function references are now equal if they refer to the same function,
and if the parameter/return type adaptation, which happens when a
reference is used where some function type is expected, is exactly the
same. This includes the number of expected positional parameters (which
can be affected by defaults/varargs), whether the coercion of vararg
parameter to Array type happened, and whether the coercion of return
type to Unit happened.

 #KT-37543 Fixed
This commit is contained in:
Alexander Udalov
2020-03-16 22:26:46 +01:00
committed by Alexander Udalov
parent c344b85d4e
commit 3269a7e693
24 changed files with 942 additions and 22 deletions
@@ -2194,6 +2194,74 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata("compiler/testData/codegen/box/callableReference/equality")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Equality extends AbstractBlackBoxCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInEquality() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/equality"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("capturedDefaults.kt")
public void testCapturedDefaults() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/capturedDefaults.kt");
}
@TestMetadata("capturedVararg.kt")
public void testCapturedVararg() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/capturedVararg.kt");
}
@TestMetadata("coercionToUnit.kt")
public void testCoercionToUnit() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/coercionToUnit.kt");
}
@TestMetadata("coercionToUnitWithDefaults.kt")
public void testCoercionToUnitWithDefaults() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/coercionToUnitWithDefaults.kt");
}
@TestMetadata("coercionToUnitWithVararg.kt")
public void testCoercionToUnitWithVararg() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/coercionToUnitWithVararg.kt");
}
@TestMetadata("extensionReceiverVsDefault.kt")
public void testExtensionReceiverVsDefault() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/extensionReceiverVsDefault.kt");
}
@TestMetadata("noCoercionToUnitIfFunctionAlreadyReturnsUnit.kt")
public void testNoCoercionToUnitIfFunctionAlreadyReturnsUnit() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/noCoercionToUnitIfFunctionAlreadyReturnsUnit.kt");
}
@TestMetadata("simpleEquality.kt")
public void testSimpleEquality() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/simpleEquality.kt");
}
@TestMetadata("varargAsArrayMemberOrExtension.kt")
public void testVarargAsArrayMemberOrExtension() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/varargAsArrayMemberOrExtension.kt");
}
@TestMetadata("varargAsArrayWithDefaults.kt")
public void testVarargAsArrayWithDefaults() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/varargAsArrayWithDefaults.kt");
}
@TestMetadata("varargWithDefaults.kt")
public void testVarargWithDefaults() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/equality/varargWithDefaults.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/callableReference/function")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -25267,6 +25335,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@TestMetadata("adaptedCallableReferencesNotEqualToCallablesFromAPI.kt")
public void testAdaptedCallableReferencesNotEqualToCallablesFromAPI() throws Exception {
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/adaptedCallableReferencesNotEqualToCallablesFromAPI.kt");
}
public void testAllFilesPresentInMethodsFromAny() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/methodsFromAny"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}