Generate correct $default method for actual suspend function

In order to do this, we need to get initial expect suspend function
before generating default value parameters checks.
 #KT-43587 Fixed
This commit is contained in:
Ilmir Usmanov
2020-12-07 08:55:28 +01:00
parent 0dc5f3ac00
commit 7f51f57998
9 changed files with 66 additions and 1 deletions
@@ -1221,7 +1221,12 @@ public class FunctionCodegen {
// 'null' because the "could not find expected declaration" error has been already reported in isDefaultNeeded earlier
List<ValueParameterDescriptor> valueParameters =
CodegenUtil.getFunctionParametersForDefaultValueGeneration(functionDescriptor, null);
functionDescriptor.isSuspend()
? CollectionsKt.plus(
CodegenUtil.getFunctionParametersForDefaultValueGeneration(
CoroutineCodegenUtilKt.unwrapInitialDescriptorForSuspendFunction(functionDescriptor), null),
CollectionsKt.last(functionDescriptor.getValueParameters()))
: CodegenUtil.getFunctionParametersForDefaultValueGeneration(functionDescriptor, null);
boolean isStatic = isStaticMethod(methodContext.getContextKind(), functionDescriptor);
FrameMap frameMap = createFrameMap(state, signature, functionDescriptor.getExtensionReceiverParameter(), valueParameters, isStatic);
@@ -7356,6 +7356,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
}
@TestMetadata("defaultExpect.kt")
public void testDefaultExpect() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
}
@TestMetadata("delegate.kt")
public void testDelegate_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines");
@@ -0,0 +1,25 @@
// !LANGUAGE: +MultiPlatformProjects
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
import kotlin.coroutines.*
var res = 0L
expect suspend fun withLimit(limit: Long = 42L)
actual suspend fun withLimit(limit: Long) {
res = limit
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {})
}
fun box(): String {
builder {
withLimit()
}
return if (res == 42L) "OK" else "FAIL $res"
}
@@ -7951,6 +7951,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
}
@TestMetadata("defaultExpect.kt")
public void testDefaultExpect() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
}
@TestMetadata("delegate.kt")
public void testDelegate_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines.experimental");
@@ -7956,6 +7956,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
}
@TestMetadata("defaultExpect.kt")
public void testDefaultExpect() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
}
@TestMetadata("delegate.kt")
public void testDelegate_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines.experimental");
@@ -7356,6 +7356,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
}
@TestMetadata("defaultExpect.kt")
public void testDefaultExpect() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
}
@TestMetadata("delegate.kt")
public void testDelegate_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines");
@@ -6121,6 +6121,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
}
@TestMetadata("defaultExpect.kt")
public void testDefaultExpect() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
}
@TestMetadata("delegate.kt")
public void testDelegate_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines");
@@ -6121,6 +6121,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
}
@TestMetadata("defaultExpect.kt")
public void testDefaultExpect() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
}
@TestMetadata("delegate.kt")
public void testDelegate_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines");
@@ -6121,6 +6121,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/breakWithNonEmptyStack.kt", "kotlin.coroutines");
}
@TestMetadata("defaultExpect.kt")
public void testDefaultExpect() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/defaultExpect.kt");
}
@TestMetadata("delegate.kt")
public void testDelegate_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/delegate.kt", "kotlin.coroutines");