diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index ff6461e89ba..0a3a0364961 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -726,7 +726,7 @@ public class AsmUtil { if (descriptor.isOperator()) { ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter(); if (receiverParameter != null) { - genParamAssertion(v, state.getTypeMapper(), frameMap, receiverParameter, "$receiver"); + genParamAssertion(v, state.getTypeMapper(), frameMap, receiverParameter, "$receiver", descriptor); } } return; @@ -734,11 +734,11 @@ public class AsmUtil { ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter(); if (receiverParameter != null) { - genParamAssertion(v, state.getTypeMapper(), frameMap, receiverParameter, "$receiver"); + genParamAssertion(v, state.getTypeMapper(), frameMap, receiverParameter, "$receiver", descriptor); } for (ValueParameterDescriptor parameter : descriptor.getValueParameters()) { - genParamAssertion(v, state.getTypeMapper(), frameMap, parameter, parameter.getName().asString()); + genParamAssertion(v, state.getTypeMapper(), frameMap, parameter, parameter.getName().asString(), descriptor); } } @@ -747,7 +747,8 @@ public class AsmUtil { @NotNull KotlinTypeMapper typeMapper, @NotNull FrameMap frameMap, @NotNull ParameterDescriptor parameter, - @NotNull String name + @NotNull String name, + @NotNull FunctionDescriptor containingDeclaration ) { KotlinType type = parameter.getType(); if (isNullableType(type) || InlineClassesUtilsKt.isNullableUnderlyingType(type)) return; @@ -755,7 +756,8 @@ public class AsmUtil { Type asmType = typeMapper.mapType(type); if (asmType.getSort() == Type.OBJECT || asmType.getSort() == Type.ARRAY) { StackValue value; - if (JvmCodegenUtil.isDeclarationOfBigArityFunctionInvoke(parameter.getContainingDeclaration())) { + if (JvmCodegenUtil.isDeclarationOfBigArityFunctionInvoke(containingDeclaration) || + JvmCodegenUtil.isDeclarationOfBigArityCreateCoroutineMethod(containingDeclaration)) { int index = getIndexOfParameterInVarargInvokeArray(parameter); value = StackValue.arrayElement( OBJECT_TYPE, null, StackValue.local(1, getArrayType(OBJECT_TYPE)), StackValue.constant(index) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java index f40eef3ca4c..f7081d1154a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.codegen.context.RootContext; import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; import org.jetbrains.kotlin.descriptors.*; +import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor; import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor; import org.jetbrains.kotlin.load.java.JvmAbi; import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor; @@ -46,6 +47,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions; import java.io.File; +import static org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenUtilKt.SUSPEND_FUNCTION_CREATE_METHOD_NAME; import static org.jetbrains.kotlin.descriptors.ClassKind.ANNOTATION_CLASS; import static org.jetbrains.kotlin.descriptors.ClassKind.INTERFACE; import static org.jetbrains.kotlin.descriptors.Modality.ABSTRACT; @@ -358,6 +360,12 @@ public class JvmCodegenUtil { return descriptor instanceof FunctionInvokeDescriptor && ((FunctionInvokeDescriptor) descriptor).hasBigArity(); } + public static boolean isDeclarationOfBigArityCreateCoroutineMethod(@Nullable DeclarationDescriptor descriptor) { + return descriptor instanceof SimpleFunctionDescriptor && descriptor.getName().asString().equals(SUSPEND_FUNCTION_CREATE_METHOD_NAME) && + ((SimpleFunctionDescriptor) descriptor).getValueParameters().size() >= FunctionInvokeDescriptor.BIG_ARITY - 1 && + descriptor.getContainingDeclaration() instanceof AnonymousFunctionDescriptor && ((AnonymousFunctionDescriptor) descriptor.getContainingDeclaration()).isSuspend(); + } + public static boolean isOverrideOfBigArityFunctionInvoke(@Nullable DeclarationDescriptor descriptor) { return descriptor instanceof FunctionDescriptor && descriptor.getName().equals(OperatorNameConventions.INVOKE) && diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt index 7ef27ea3f79..1e59e475bce 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/CoroutineCodegen.kt @@ -338,6 +338,7 @@ class CoroutineCodegenForLambda private constructor( val owner = typeMapper.mapClass(classDescriptor) val thisInstance = StackValue.thisOrOuter(codegen, classDescriptor, false, false) + val isBigArity = JvmCodegenUtil.isDeclarationOfBigArityCreateCoroutineMethod(createCoroutineDescriptor) with(codegen.v) { anew(owner) @@ -350,10 +351,16 @@ class CoroutineCodegenForLambda private constructor( } // load resultContinuation - if (generateErasedCreate) { - load(allFunctionParameters().size + 1, AsmTypes.OBJECT_TYPE) + if (isBigArity) { + load(1, AsmTypes.OBJECT_TYPE) + iconst(allFunctionParameters().size) + aload(AsmTypes.OBJECT_TYPE) } else { - load(allFunctionParameters().map { typeMapper.mapType(it.type).size }.sum() + 1, AsmTypes.OBJECT_TYPE) + if (generateErasedCreate) { + load(allFunctionParameters().size + 1, AsmTypes.OBJECT_TYPE) + } else { + load(allFunctionParameters().map { typeMapper.mapType(it.type).size }.sum() + 1, AsmTypes.OBJECT_TYPE) + } } invokespecial(owner.internalName, constructorToUseFromInvoke.name, constructorToUseFromInvoke.descriptor, false) @@ -365,20 +372,33 @@ class CoroutineCodegenForLambda private constructor( var index = 1 for (parameter in allFunctionParameters()) { val fieldInfoForCoroutineLambdaParameter = parameter.getFieldInfoForCoroutineLambdaParameter() - if (generateErasedCreate) { - load(index, AsmTypes.OBJECT_TYPE) + if (isBigArity) { + load(cloneIndex, fieldInfoForCoroutineLambdaParameter.ownerType) + load(1, AsmTypes.OBJECT_TYPE) + iconst(index - 1) + aload(AsmTypes.OBJECT_TYPE) StackValue.coerce(AsmTypes.OBJECT_TYPE, fieldInfoForCoroutineLambdaParameter.fieldType, this) + putfield( + fieldInfoForCoroutineLambdaParameter.ownerInternalName, + fieldInfoForCoroutineLambdaParameter.fieldName, + fieldInfoForCoroutineLambdaParameter.fieldType.descriptor + ) } else { - load(index, fieldInfoForCoroutineLambdaParameter.fieldType) + if (generateErasedCreate) { + load(index, AsmTypes.OBJECT_TYPE) + StackValue.coerce(AsmTypes.OBJECT_TYPE, fieldInfoForCoroutineLambdaParameter.fieldType, this) + } else { + load(index, fieldInfoForCoroutineLambdaParameter.fieldType) + } + AsmUtil.genAssignInstanceFieldFromParam( + fieldInfoForCoroutineLambdaParameter, + index, + this, + cloneIndex, + generateErasedCreate + ) } - AsmUtil.genAssignInstanceFieldFromParam( - fieldInfoForCoroutineLambdaParameter, - index, - this, - cloneIndex, - generateErasedCreate - ) - index += fieldInfoForCoroutineLambdaParameter.fieldType.size + index += if (isBigArity || generateErasedCreate) 1 else fieldInfoForCoroutineLambdaParameter.fieldType.size } load(cloneIndex, AsmTypes.OBJECT_TYPE) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index f3fe4e2e9f2..a17016e538d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -1203,7 +1203,7 @@ public class KotlinTypeMapper { skipGenericSignature); } - if (isDeclarationOfBigArityFunctionInvoke(f)) { + if (isDeclarationOfBigArityFunctionInvoke(f) || isDeclarationOfBigArityCreateCoroutineMethod(f)) { KotlinBuiltIns builtIns = DescriptorUtilsKt.getBuiltIns(f); KotlinType arrayOfNullableAny = builtIns.getArrayType(Variance.INVARIANT, builtIns.getNullableAnyType()); return mapSignatureWithCustomParameters(f, kind, Stream.of(arrayOfNullableAny), false, false); diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt new file mode 100644 index 00000000000..2b92cd69b11 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt @@ -0,0 +1,27 @@ +// IGNORE_BACKEND: JVM_IR +// WITH_RUNTIME +// WITH_COROUTINES +// COMMON_COROUTINES_TEST +// CHECK_BYTECODE_LISTING + +import helpers.* +import COROUTINES_PACKAGE.* + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +suspend fun call(c: suspend Long.() -> String): String { + return 1000L.c() +} + +fun box(): String { + var res = "" + builder { + res = call { -> + "OK$this" + } + } + if (res != "OK1000") return res + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.txt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.txt new file mode 100644 index 00000000000..3e78fc7681d --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.txt @@ -0,0 +1,34 @@ +@kotlin.coroutines.jvm.internal.DebugMetadata +@kotlin.Metadata +final class LambdaWithLongReceiverKt$box$1$1 { + field label: int + private field p$: long + inner class LambdaWithLongReceiverKt$box$1 + inner class LambdaWithLongReceiverKt$box$1$1 + method (p0: kotlin.coroutines.Continuation): void + public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation + public final method invoke(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public final @org.jetbrains.annotations.Nullable method invokeSuspend(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object +} + +@kotlin.coroutines.jvm.internal.DebugMetadata +@kotlin.Metadata +final class LambdaWithLongReceiverKt$box$1 { + synthetic final field $res: kotlin.jvm.internal.Ref$ObjectRef + field L$0: java.lang.Object + field label: int + inner class LambdaWithLongReceiverKt$box$1 + inner class LambdaWithLongReceiverKt$box$1$1 + method (p0: kotlin.jvm.internal.Ref$ObjectRef, p1: kotlin.coroutines.Continuation): void + public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation + public final method invoke(p0: java.lang.Object): java.lang.Object + public final @org.jetbrains.annotations.Nullable method invokeSuspend(@org.jetbrains.annotations.NotNull p0: java.lang.Object): java.lang.Object +} + +@kotlin.Metadata +public final class LambdaWithLongReceiverKt { + inner class LambdaWithLongReceiverKt$box$1 + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void + public final static @org.jetbrains.annotations.Nullable method call(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): java.lang.Object +} diff --git a/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_1_2.txt b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_1_2.txt new file mode 100644 index 00000000000..00c3aa1f737 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver_1_2.txt @@ -0,0 +1,30 @@ +@kotlin.Metadata +final class LambdaWithLongReceiverKt$box$1$1 { + private field p$: long + inner class LambdaWithLongReceiverKt$box$1 + inner class LambdaWithLongReceiverKt$box$1$1 + method (p0: kotlin.coroutines.experimental.Continuation): void + public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.experimental.Continuation): kotlin.coroutines.experimental.Continuation + public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object + public final method invoke(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object +} + +@kotlin.Metadata +final class LambdaWithLongReceiverKt$box$1 { + synthetic final field $res: kotlin.jvm.internal.Ref$ObjectRef + field L$0: java.lang.Object + inner class LambdaWithLongReceiverKt$box$1 + inner class LambdaWithLongReceiverKt$box$1$1 + method (p0: kotlin.jvm.internal.Ref$ObjectRef, p1: kotlin.coroutines.experimental.Continuation): void + public final @org.jetbrains.annotations.NotNull method create(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.experimental.Continuation): kotlin.coroutines.experimental.Continuation + public final @org.jetbrains.annotations.Nullable method doResume(@org.jetbrains.annotations.Nullable p0: java.lang.Object, @org.jetbrains.annotations.Nullable p1: java.lang.Throwable): java.lang.Object + public final method invoke(p0: java.lang.Object): java.lang.Object +} + +@kotlin.Metadata +public final class LambdaWithLongReceiverKt { + inner class LambdaWithLongReceiverKt$box$1 + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String + public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void + public final static @org.jetbrains.annotations.Nullable method call(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function2, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.experimental.Continuation): java.lang.Object +} diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt new file mode 100644 index 00000000000..95a017da1ee --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt @@ -0,0 +1,47 @@ +// !LANGUAGE: +ReleaseCoroutines +// IGNORE_BACKEND: JS_IR, JS, NATIVE, JVM_IR +// WITH_REFLECT +// WITH_COROUTINES + +import kotlin.reflect.full.* +import helpers.* +import kotlin.coroutines.* + +class A { + suspend fun foo( + p00: Long = 0, p01: A = A(), p02: A = A(), p03: A = A(), p04: A = A(), p05: A = A(), p06: A = A(), p07: A = A(), p08: A = A(), p09: A = A(), + p10: A = A(), p11: A = A(), p12: A = A(), p13: A = A(), p14: A = A(), p15: A = A(), p16: A = A(), p17: A = A(), p18: A = A(), p19: A = A(), + p20: A = A(), p21: A = A(), p22: A = A(), p23: A = A(), p24: A = A(), p25: A = A(), p26: A = A(), p27: A = A(), p28: A = A(), p29: String + ): String { + return p29 + p00 + } +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +suspend fun expectsLambdaWithBigArity(c: suspend (Long, Long, Long, Long, Long, Long, Long, Long, Long, Long, + Long, Long, Long, Long, Long, Long, Long, Long, Long, Long, + Long, Long, Long, Long, Long, Long, Long, Long, Long, String) -> String): String { + return c.invoke(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, "OK") +} + +fun box(): String { + val a = A() + var res = "FAIL 1" + builder { + res = A::foo.callSuspend(a, 1L, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, "OK") + } + if (res != "OK1") return res + res = "FAIL 2" + builder { + res = A::foo.callSuspendBy(mapOf(A::foo.parameters.first() to A(), A::foo.parameters.last() to "OK")) as String + } + if (res != "OK0") return res + res = "FAIL 3" + builder { + res = expectsLambdaWithBigArity { _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, s -> s } + } + return res +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.kt new file mode 100644 index 00000000000..f473dc831fc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: -FunctionTypesWithBigArity +// !DIAGNOSTICS: -UNUSED_PARAMETER +// SKIP_TXT + +class A { + suspend fun foo( + p00: Long = 1, p01: A = A(), p02: A = A(), p03: A = A(), p04: A = A(), p05: A = A(), p06: A = A(), p07: A = A(), p08: A = A(), p09: A = A(), + p10: A = A(), p11: A = A(), p12: A = A(), p13: A = A(), p14: A = A(), p15: A = A(), p16: A = A(), p17: A = A(), p18: A = A(), p19: A = A(), + p20: A = A(), p21: A = A(), p22: A = A(), p23: A = A(), p24: A = A(), p25: A = A(), p26: A = A(), p27: A = A(), p28: A = A(), p29: String + ): String { + return p29 + } +} + +suspend fun expectsLambdaWithBigArity(c: suspend (Long, Long, Long, Long, Long, Long, Long, Long, Long, Long, + Long, Long, Long, Long, Long, Long, Long, Long, Long, Long, + Long, Long, Long, Long, Long, Long, Long, Long, Long, String) -> String): String { + return c.invoke(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, "OK") +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index f3a879db661..2bfb740e8fc 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1664,6 +1664,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.kt"); + } + @TestMetadata("property.kt") public void testProperty_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 8985af4b296..d186009de0b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -1664,6 +1664,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/bigArity.kt"); + } + @TestMetadata("property.kt") public void testProperty_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/property.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 90dc4cd78b6..301b6579e94 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -6216,6 +6216,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/bridges"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("lambdaWithMultipleParameters.kt") public void testLambdaWithMultipleParameters_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt", "kotlin.coroutines.experimental"); @@ -6585,6 +6595,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt"); + } + @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index fc3edafe859..aec53296cd1 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -6216,6 +6216,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/bridges"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("lambdaWithMultipleParameters.kt") public void testLambdaWithMultipleParameters_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt", "kotlin.coroutines.experimental"); @@ -6585,6 +6595,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt"); + } + @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 1de3f08e9a8..80d3acf8ffd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6216,6 +6216,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/bridges"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("lambdaWithMultipleParameters.kt") public void testLambdaWithMultipleParameters_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt", "kotlin.coroutines.experimental"); @@ -6585,6 +6595,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt"); + } + @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt"); diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt index 07f6b5582e6..36c7dc4b3ef 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/builtins/jvm/JavaToKotlinClassMap.kt @@ -26,6 +26,10 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap { FunctionClassDescriptor.Kind.Function.packageFqName.toString() + "." + FunctionClassDescriptor.Kind.Function.classNamePrefix private val NUMBERED_K_FUNCTION_PREFIX = FunctionClassDescriptor.Kind.KFunction.packageFqName.toString() + "." + FunctionClassDescriptor.Kind.KFunction.classNamePrefix + private val NUMBERED_SUSPEND_FUNCTION_PREFIX = + FunctionClassDescriptor.Kind.SuspendFunction.packageFqName.toString() + "." + FunctionClassDescriptor.Kind.SuspendFunction.classNamePrefix + private val NUMBERED_K_SUSPEND_FUNCTION_PREFIX = + FunctionClassDescriptor.Kind.KSuspendFunction.packageFqName.toString() + "." + FunctionClassDescriptor.Kind.KSuspendFunction.classNamePrefix private val FUNCTION_N_CLASS_ID = ClassId.topLevel(FqName("kotlin.jvm.functions.FunctionN")) private val FUNCTION_N_FQ_NAME = FUNCTION_N_CLASS_ID.asSingleFqName() @@ -134,13 +138,19 @@ object JavaToKotlinClassMap : PlatformToKotlinClassMap { * kotlin.Nothing -> java.lang.Void * kotlin.IntArray -> null * kotlin.Function3 -> kotlin.jvm.functions.Function3 + * kotlin.SuspendFunction3 -> kotlin.jvm.functions.Function4 * kotlin.Function42 -> kotlin.jvm.functions.FunctionN + * kotlin.SuspendFunction42 -> kotlin.jvm.functions.FunctionN * kotlin.reflect.KFunction3 -> kotlin.reflect.KFunction + * kotlin.reflect.KSuspendFunction3 -> kotlin.reflect.KFunction * kotlin.reflect.KFunction42 -> kotlin.reflect.KFunction + * kotlin.reflect.KSuspendFunction42 -> kotlin.reflect.KFunction */ fun mapKotlinToJava(kotlinFqName: FqNameUnsafe): ClassId? = when { isKotlinFunctionWithBigArity(kotlinFqName, NUMBERED_FUNCTION_PREFIX) -> FUNCTION_N_CLASS_ID + isKotlinFunctionWithBigArity(kotlinFqName, NUMBERED_SUSPEND_FUNCTION_PREFIX) -> FUNCTION_N_CLASS_ID isKotlinFunctionWithBigArity(kotlinFqName, NUMBERED_K_FUNCTION_PREFIX) -> K_FUNCTION_CLASS_ID + isKotlinFunctionWithBigArity(kotlinFqName, NUMBERED_K_SUSPEND_FUNCTION_PREFIX) -> K_FUNCTION_CLASS_ID else -> kotlinToJava[kotlinFqName] } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index 155dde4d4ed..c4d99b6b5aa 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -5501,6 +5501,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/bridges"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); } + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines.experimental"); + } + @TestMetadata("lambdaWithMultipleParameters.kt") public void testLambdaWithMultipleParameters_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt", "kotlin.coroutines.experimental"); @@ -5715,6 +5720,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true); } + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt"); + } + @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index b79fed04b72..ca6fdb443c1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -5926,6 +5926,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/bridges"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_2() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines.experimental"); + } + + @TestMetadata("lambdaWithLongReceiver.kt") + public void testLambdaWithLongReceiver_1_3() throws Exception { + runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithLongReceiver.kt", "kotlin.coroutines"); + } + @TestMetadata("lambdaWithMultipleParameters.kt") public void testLambdaWithMultipleParameters_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/bridges/lambdaWithMultipleParameters.kt", "kotlin.coroutines.experimental"); @@ -6285,6 +6295,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); } + @TestMetadata("bigArity.kt") + public void testBigArity() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/bigArity.kt"); + } + @TestMetadata("fromJava.kt") public void testFromJava() throws Exception { runTest("compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/fromJava.kt");