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 1281c853ce5..b09724fc287 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 @@ -9762,6 +9762,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @Test + @TestMetadata("kt49168.kt") + public void testKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltInsOverDescriptors.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltInsOverDescriptors.kt index fc642c78feb..94a90f3d9c1 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltInsOverDescriptors.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltInsOverDescriptors.kt @@ -32,7 +32,10 @@ import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeBuilder import org.jetbrains.kotlin.ir.types.impl.buildSimpleType import org.jetbrains.kotlin.ir.types.impl.originalKotlinType -import org.jetbrains.kotlin.ir.util.* +import org.jetbrains.kotlin.ir.util.SymbolTable +import org.jetbrains.kotlin.ir.util.TypeTranslator +import org.jetbrains.kotlin.ir.util.functions +import org.jetbrains.kotlin.ir.util.referenceClassifier import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.MemberScope @@ -54,7 +57,7 @@ class IrBuiltInsOverDescriptors( get() = synchronized(this) { if (_functionFactory == null) { - _functionFactory = IrDescriptorBasedFunctionFactory(this, symbolTable) + _functionFactory = IrDescriptorBasedFunctionFactory(this, symbolTable, typeTranslator) } _functionFactory!! } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDescriptorBasedFunctionFactory.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDescriptorBasedFunctionFactory.kt index 285480cc506..ea716aeb2d8 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDescriptorBasedFunctionFactory.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDescriptorBasedFunctionFactory.kt @@ -85,6 +85,7 @@ abstract class IrAbstractDescriptorBasedFunctionFactory { class IrDescriptorBasedFunctionFactory( private val irBuiltIns: IrBuiltInsOverDescriptors, private val symbolTable: SymbolTable, + private val typeTranslator: TypeTranslator, getPackageFragment: ((PackageFragmentDescriptor) -> IrPackageFragment)? = null, // Needed for JS and Wasm backends to "preload" interfaces that can referenced during lowerings private val referenceFunctionsWhenKFunctionAreReferenced: Boolean = false, @@ -257,29 +258,16 @@ class IrDescriptorBasedFunctionFactory( } } - private fun IrClass.createThisReceiver(descriptorFactory: FunctionDescriptorFactory): IrValueParameter { - val vDescriptor = descriptorFactory.classReceiverParameterDescriptor() - val vSymbol = IrValueParameterSymbolImpl(vDescriptor) - val type = with(IrSimpleTypeBuilder()) { - classifier = symbol - arguments = typeParameters.run { - val builder = IrSimpleTypeBuilder() - mapTo(ArrayList(size)) { - builder.classifier = it.symbol - buildTypeProjection() - } - } - buildSimpleType() - } - val vDeclaration = irFactory.createValueParameter( - offset, offset, classOrigin, vSymbol, SpecialNames.THIS, -1, type, null, + private fun createThisReceiver(descriptorFactory: FunctionDescriptorFactory): IrValueParameter { + val descriptor = descriptorFactory.classReceiverParameterDescriptor() + return irFactory.createValueParameter( + offset, offset, classOrigin, IrValueParameterSymbolImpl(descriptor), SpecialNames.THIS, -1, + typeTranslator.translateType(descriptor.type), null, isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false ) - - return vDeclaration } private fun IrClass.createMembers(isK: Boolean, isSuspend: Boolean, descriptorFactory: FunctionDescriptorFactory) { @@ -435,7 +423,7 @@ class IrDescriptorBasedFunctionFactory( val r = klass.createTypeParameters(n, descriptorFactory) - klass.thisReceiver = klass.createThisReceiver(descriptorFactory).also { it.parent = klass } + klass.thisReceiver = createThisReceiver(descriptorFactory).also { it.parent = klass } klass.superTypes = listOf(with(IrSimpleTypeBuilder()) { classifier = baseClass diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt index cab39f04e98..59a1320cccd 100644 --- a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt +++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt @@ -38,7 +38,6 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrModuleSeria import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerIr import org.jetbrains.kotlin.ir.declarations.IrFactory -import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors @@ -56,7 +55,6 @@ import org.jetbrains.kotlin.konan.util.KlibMetadataFactories import org.jetbrains.kotlin.library.* import org.jetbrains.kotlin.library.impl.BuiltInsPlatform import org.jetbrains.kotlin.library.impl.buildKotlinLibrary -import org.jetbrains.kotlin.library.resolver.KotlinResolvedLibrary import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.progress.IncrementalNextRoundException import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus @@ -429,6 +427,7 @@ fun getIrModuleInfoForKlib( irBuiltIns.functionFactory = IrDescriptorBasedFunctionFactory( irBuiltIns, symbolTable, + typeTranslator, if (loadFunctionInterfacesIntoStdlib) getFunctionFactoryCallback(deserializedModuleFragments.first()) else null, true ) @@ -483,6 +482,7 @@ fun getIrModuleInfoForSourceFiles( IrDescriptorBasedFunctionFactory( irBuiltIns, symbolTable, + psi2IrContext.typeTranslator, if (loadFunctionInterfacesIntoStdlib) getFunctionFactoryCallback(deserializedModuleFragments.first()) else null, true ) diff --git a/compiler/testData/codegen/box/coroutines/kt49168.kt b/compiler/testData/codegen/box/coroutines/kt49168.kt new file mode 100644 index 00000000000..9d85ceba0e9 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/kt49168.kt @@ -0,0 +1,27 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS + +import helpers.* +import kotlin.coroutines.* + +fun interface Print { + suspend fun print(msg: String): String +} + +object Context : Print by Print(::id) + +fun id(x: String): String = x + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var result = "Fail" + builder { + result = Context.print("OK") + } + return result +} 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 644e5149756..1d11c811c5b 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 @@ -9684,6 +9684,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @Test + @TestMetadata("kt49168.kt") + public void testKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() 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 acd23135403..e54969742fa 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 @@ -9762,6 +9762,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @Test + @TestMetadata("kt49168.kt") + public void testKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() 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 d9d4305b1d2..79aafcaa2b6 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7230,6 +7230,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/kt24135.kt"); } + @TestMetadata("kt49168.kt") + public void ignoreKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @TestMetadata("suspendFunctionAsSupertype.kt") public void ignoreSuspendFunctionAsSupertype() throws Exception { runTest("compiler/testData/codegen/box/coroutines/suspendFunctionAsSupertype.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 82eb1d435e1..00d226d691f 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -6752,6 +6752,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @TestMetadata("kt49168.kt") + public void testKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 39a49f135c5..ce0c765fb6e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -5981,6 +5981,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @TestMetadata("kt49168.kt") + public void testKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { runTest("compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrJsCodegenBoxTestGenerated.java index b78fecfdc12..21de9ceb5d6 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrJsCodegenBoxTestGenerated.java @@ -6998,6 +6998,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @Test + @TestMetadata("kt49168.kt") + public void testKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/JsCodegenBoxTestGenerated.java index 74ef27bd964..8d73c36cc30 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/JsCodegenBoxTestGenerated.java @@ -6956,6 +6956,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @Test + @TestMetadata("kt49168.kt") + public void testKt49168() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); + } + @Test @TestMetadata("lastExpressionIsLoop.kt") public void testLastExpressionIsLoop() throws Exception {