JVM IR: do not copy type parameters into suspend lambda classes

Declarations inside that class are referencing the type parameters of
the containing function anyway, since we don't do any remapping. So the
resulting IR is slightly more correct, and doesn't lead to type
parameter/argument size mismatch error on IrBased/Wrapped-descriptors.

This reverts a part of 01da7f289b, which looks like it was no longer
necessary after 8d0ffa1444.

 #KT-42028 Fixed
This commit is contained in:
Alexander Udalov
2020-09-18 17:03:50 +02:00
parent bdf502edef
commit d48307ec34
10 changed files with 70 additions and 5 deletions
@@ -6713,6 +6713,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/coroutines/kt35967.kt");
}
@TestMetadata("kt42028.kt")
public void testKt42028() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt42028.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");
@@ -135,9 +135,6 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
"Inconsistency between callable reference to suspend lambda and the corresponding continuation"
}
+irCall(constructor.symbol).apply {
for (typeParameter in constructor.parentAsClass.typeParameters) {
putTypeArgument(typeParameter.index, expression.getTypeArgument(typeParameter.index))
}
expressionArguments.forEachIndexed { index, argument ->
putValueArgument(index, argument)
}
@@ -166,7 +163,6 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
if (insideInlineFunction) DescriptorVisibilities.PUBLIC else JavaDescriptorVisibilities.PACKAGE_VISIBILITY
).apply {
copyAttributes(info.reference)
copyTypeParametersFrom(info.function)
val functionNClass = context.ir.symbols.getJvmFunctionClass(info.arity + 1)
superTypes +=
IrSimpleTypeImpl(
+34
View File
@@ -0,0 +1,34 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.*
import helpers.*
interface I {
suspend fun foo(g: suspend String.() -> Unit)
}
fun builder0(f: suspend () -> Unit) {
f.startCoroutine(EmptyContinuation)
}
fun <T> builder(f: suspend I.() -> T) {
builder0 {
f(object : I {
override suspend fun foo(g: suspend String.() -> Unit) {
g("OK")
"Force non-tail call".length
}
})
}
}
fun box(): String {
var result = "Fail"
builder {
foo {
result = this
}
}
return result
}
@@ -6968,6 +6968,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/kt35967.kt");
}
@TestMetadata("kt42028.kt")
public void testKt42028() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt42028.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental");
@@ -6968,6 +6968,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/kt35967.kt");
}
@TestMetadata("kt42028.kt")
public void testKt42028() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt42028.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_2() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines.experimental");
@@ -6713,6 +6713,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/kt35967.kt");
}
@TestMetadata("kt42028.kt")
public void testKt42028() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt42028.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");
@@ -88,7 +88,7 @@ class IndexedParametersSubstitution(
) : TypeSubstitution() {
init {
assert(parameters.size <= arguments.size) {
"Number of arguments should not be less then number of parameters, but: parameters=${parameters.size}, args=${arguments.size}"
"Number of arguments should not be less than number of parameters, but: parameters=${parameters.size}, args=${arguments.size}"
}
}
@@ -5583,6 +5583,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/coroutines/kt35967.kt");
}
@TestMetadata("kt42028.kt")
public void testKt42028() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt42028.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");
@@ -5583,6 +5583,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/kt35967.kt");
}
@TestMetadata("kt42028.kt")
public void testKt42028() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt42028.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");
@@ -5583,6 +5583,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/coroutines/kt35967.kt");
}
@TestMetadata("kt42028.kt")
public void testKt42028() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/kt42028.kt");
}
@TestMetadata("lastExpressionIsLoop.kt")
public void testLastExpressionIsLoop_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt", "kotlin.coroutines");