diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 490b71d337a..fdbc6ed5fd8 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -21431,6 +21431,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/invokedynamic/sam/kt45779.kt"); } + @Test + @TestMetadata("kt47510.kt") + public void testKt47510() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/kt47510.kt"); + } + @Test @TestMetadata("nullabilityAssertions.kt") public void testNullabilityAssertions() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index b0d9c7f6fb7..4ac35242ce0 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -670,9 +670,14 @@ class ExpressionCodegen( // Otherwise, we need to treat `Result` as boxed if it overrides a non-`Result` or boxed `Result` type. // TODO: if results of `needsResultArgumentUnboxing` for `overriddenSymbols` are inconsistent, the boxedness // of the `Result` depends on which overridden function is called. This is probably unfixable. - return parentAsClass.functions.none { - it != this && it.origin == IrDeclarationOrigin.BRIDGE && it.attributeOwnerId == attributeOwnerId - } && overriddenSymbols.any { it.owner.resultIsActuallyAny(index) != false } + val parent = this.parent + return parent is IrClass && + parent.functions.none { + it != this && it.origin == IrDeclarationOrigin.BRIDGE && it.attributeOwnerId == attributeOwnerId + } && + overriddenSymbols.any { + it.owner.resultIsActuallyAny(index) != false + } } override fun visitFieldAccess(expression: IrFieldAccessExpression, data: BlockInfo): PromisedValue { diff --git a/compiler/testData/codegen/box/invokedynamic/sam/kt47510.kt b/compiler/testData/codegen/box/invokedynamic/sam/kt47510.kt new file mode 100644 index 00000000000..eef434003a1 --- /dev/null +++ b/compiler/testData/codegen/box/invokedynamic/sam/kt47510.kt @@ -0,0 +1,19 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FULL_JDK + +import java.util.concurrent.Executor +import kotlin.coroutines.Continuation +import kotlin.coroutines.CoroutineContext + +class Wrapper(val pool: Executor, private val cont: Continuation) : Continuation { + override val context: CoroutineContext + get() = cont.context + + override fun resumeWith(result: Result) { + // Check that there's no compiler exception here + pool.execute { cont.resumeWith(result) } + } +} + +fun box() = "OK" diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 80524f8c49f..e22d8a3a038 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -21389,6 +21389,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/invokedynamic/sam/kt45779.kt"); } + @Test + @TestMetadata("kt47510.kt") + public void testKt47510() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/kt47510.kt"); + } + @Test @TestMetadata("nullabilityAssertions.kt") public void testNullabilityAssertions() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index f56f12735e0..a77702910a1 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -21431,6 +21431,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/invokedynamic/sam/kt45779.kt"); } + @Test + @TestMetadata("kt47510.kt") + public void testKt47510() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/kt47510.kt"); + } + @Test @TestMetadata("nullabilityAssertions.kt") public void testNullabilityAssertions() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1fef11db3a2..fcea44f75cb 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -17874,6 +17874,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/invokedynamic/sam/kt45779.kt"); } + @TestMetadata("kt47510.kt") + public void testKt47510() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/kt47510.kt"); + } + @TestMetadata("nullabilityAssertions.kt") public void testNullabilityAssertions() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/nullabilityAssertions.kt");