From 86b5c63891af01e408d730d9148a8309d414d594 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Wed, 13 May 2020 19:31:25 +0300 Subject: [PATCH] JS IR: fix origin for callable references with bound reciever In case of IrFunctionReference with type SuspendFunction (no K!) there was a misalignment between the base class (Any) and the origin (LAMBDA..). As a result the SuspendFunctionLowering was getting confused and produced hanging code. --- .../ir/backend/js/lower/CallableReferenceLowering.kt | 2 +- .../adaptedReferences/suspendConversion/bound.kt | 2 -- .../adaptedReferences/suspendConversion/inlineBound.kt | 2 -- .../callableReference/equality/suspendConversion.kt | 2 +- .../test/ir/semantics/IrJsCodegenBoxTestGenerated.java | 10 ++++++++++ .../js/test/semantics/JsCodegenBoxTestGenerated.java | 10 ++++++++++ 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt index 5ffd163e8b7..ce6be3e82c0 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt @@ -122,7 +122,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod visibility = Visibilities.LOCAL // A callable reference results in a synthetic class, while a lambda is not synthetic. // We don't produce GENERATED_SAM_IMPLEMENTATION, which is always synthetic. - origin = if (isKReference) FUNCTION_REFERENCE_IMPL else LAMBDA_IMPL + origin = if (isKReference || !isLambda) FUNCTION_REFERENCE_IMPL else LAMBDA_IMPL name = SpecialNames.NO_NAME_PROVIDED }.apply { superTypes = listOf(superClass, reference.type) diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt index f27ba87a7bf..d68dbd4b957 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt @@ -2,8 +2,6 @@ // WITH_RUNTIME // WITH_COROUTINES // IGNORE_BACKEND_FIR: JVM_IR -// TARGET_BACKEND: JVM -// ^ this test hangs on JS_IR (even if it's IGNOREd) // IGNORE_BACKEND: JVM_IR import helpers.* diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt index 24e135ee730..0b7bc0aac86 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt @@ -2,8 +2,6 @@ // WITH_RUNTIME // WITH_COROUTINES // IGNORE_BACKEND_FIR: JVM_IR -// TARGET_BACKEND: JVM -// ^ this test hangs on JS_IR (even if it's IGNOREd) // IGNORE_BACKEND: JVM_IR import helpers.* diff --git a/compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt b/compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt index f6aed0e40b5..91c255c3d2d 100644 --- a/compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt +++ b/compiler/testData/codegen/box/callableReference/equality/suspendConversion.kt @@ -1,6 +1,6 @@ // !LANGUAGE: +SuspendConversion // IGNORE_BACKEND_FIR: JVM_IR -// IGNORE_BACKEND: JVM_IR, JS_IR +// IGNORE_BACKEND: JVM_IR // ^ TODO fix suspend coercion for bound function references in JVM_IR // FILE: suspendCovnersion.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 9ba307ec715..26f9cc669ac 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -1577,6 +1577,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @TestMetadata("bound.kt") + public void testBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt"); + } + @TestMetadata("crossInline.kt") public void testCrossInline() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); @@ -1597,6 +1602,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); } + @TestMetadata("inlineBound.kt") + public void testInlineBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt"); + } + @TestMetadata("inlineSimple.kt") public void testInlineSimple() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.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 aacc2e07597..a636a60b113 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 @@ -1577,6 +1577,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @TestMetadata("bound.kt") + public void testBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/bound.kt"); + } + @TestMetadata("crossInline.kt") public void testCrossInline() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/crossInline.kt"); @@ -1597,6 +1602,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineAdaptedWithVarargs.kt"); } + @TestMetadata("inlineBound.kt") + public void testInlineBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineBound.kt"); + } + @TestMetadata("inlineSimple.kt") public void testInlineSimple() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/suspendConversion/inlineSimple.kt");