[NI] Commonize type-conversions (SAM/Suspend)

- Allow participating subtypes of functional types in conversions
 - Fix several subtle inconsistencies
 - Place logic about conversions at one place

 Now conversions operations have two stages: before usual subtyping
 check and after one. This is needed to support conversions of
 subtypes (of functional types, for example). First, the compiler
 checks if it possible to resolve an argument without conversion and
 only then it tries to perform conversion.
 Note that it'd be incorrect to perform conversion eagerly as it can
 change resolve (Runnable & () -> Unit <: KRunnable), plus we can't
 guess whether conversion is needed at all as it's important not to
 look into supertypes if resolution doesn't actually needed it

 #KT-36448 Fixed
 #KT-37574 Fixed
 #KT-38604 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-05-15 15:27:37 +03:00
parent f702da5c51
commit 8bdc4d34f7
24 changed files with 636 additions and 107 deletions
@@ -8904,10 +8904,20 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("intersectionTypeToSubtypeConversion.kt")
public void testIntersectionTypeToSubtypeConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/intersectionTypeToSubtypeConversion.kt");
}
@TestMetadata("onArgument.kt")
public void testOnArgument() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/onArgument.kt");
}
@TestMetadata("subtypeOfFunctionalTypeToSuspendConversion.kt")
public void testSubtypeOfFunctionalTypeToSuspendConversion() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendConversion/subtypeOfFunctionalTypeToSuspendConversion.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine")
@@ -12385,6 +12395,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/funInterface/inlinedSamWrapper.kt");
}
@TestMetadata("intersectionTypeToFunInterfaceConversion.kt")
public void testIntersectionTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/intersectionTypeToFunInterfaceConversion.kt");
}
@TestMetadata("multimodule.kt")
public void testMultimodule() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/multimodule.kt");
@@ -12415,6 +12430,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/funInterface/samConstructorExplicitInvocation.kt");
}
@TestMetadata("subtypeOfFunctionalTypeToFunInterfaceConversion.kt")
public void testSubtypeOfFunctionalTypeToFunInterfaceConversion() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/subtypeOfFunctionalTypeToFunInterfaceConversion.kt");
}
@TestMetadata("suspendFunInterfaceConversionCodegen.kt")
public void testSuspendFunInterfaceConversionCodegen() throws Exception {
runTest("compiler/testData/codegen/box/funInterface/suspendFunInterfaceConversionCodegen.kt");
@@ -29659,6 +29679,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/sam/partialSamKT.kt");
}
@TestMetadata("passSubtypeOfFunctionSamConversion.kt")
public void testPassSubtypeOfFunctionSamConversion() throws Exception {
runTest("compiler/testData/codegen/box/sam/passSubtypeOfFunctionSamConversion.kt");
}
@TestMetadata("predicateSamWrapper.kt")
public void testPredicateSamWrapper() throws Exception {
runTest("compiler/testData/codegen/box/sam/predicateSamWrapper.kt");