diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt index 264666d9484..b0ac5ec76df 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.ClassLoweringPass import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor import org.jetbrains.kotlin.backend.common.ir.copyTo +import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.builders.* @@ -227,11 +228,6 @@ class InlineClassLowering(val context: BackendContext) { private fun createStaticBodilessMethod(function: IrFunction): IrSimpleFunction { val descriptor = WrappedSimpleFunctionDescriptor() - val returnType = when (function) { - is IrSimpleFunction -> function.returnType - is IrConstructor -> function.parentAsClass.defaultType - else -> error("Unknown function type") - } return IrFunctionImpl( function.startOffset, @@ -241,7 +237,7 @@ class InlineClassLowering(val context: BackendContext) { function.name.toInlineClassImplementationName(), function.visibility, Modality.FINAL, - returnType, + function.returnType, function.isInline, function.isExternal, (function is IrSimpleFunction && function.isTailrec), diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt index f0982c1645e..57a76106e61 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.backend.common.ClassLoweringPass import org.jetbrains.kotlin.backend.common.bridges.FunctionHandle import org.jetbrains.kotlin.backend.common.bridges.generateBridges import org.jetbrains.kotlin.backend.common.ir.copyTo -import org.jetbrains.kotlin.backend.common.ir.isStatic +import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom import org.jetbrains.kotlin.backend.common.ir.isSuspend import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.lower.irBlockBody @@ -120,7 +120,7 @@ class BridgesConstruction(val context: JsIrBackendContext) : ClassLoweringPass { IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also { it.parent = this@apply } } extensionReceiverParameter = bridge.extensionReceiverParameter?.copyTo(this) - typeParameters += bridge.typeParameters + copyTypeParametersFrom(bridge) valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) } annotations += bridge.annotations overriddenSymbols.addAll(delegateTo.overriddenSymbols) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableSuccessorsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableSuccessorsLowering.kt index 6f703ecc403..d06f4e3e626 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableSuccessorsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/ThrowableSuccessorsLowering.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.backend.js.lower import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.atMostOne import org.jetbrains.kotlin.backend.common.descriptors.WrappedPropertyDescriptor +import org.jetbrains.kotlin.backend.common.ir.copyTo import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement @@ -183,7 +184,7 @@ class ThrowableSuccessorsLowering(context: JsIrBackendContext) : FileLoweringPas val function = JsIrBuilder.buildFunction(name, fakeAccessor.returnType, fakeAccessor.parent).apply { overriddenSymbols += fakeAccessor.overriddenSymbols correspondingProperty = fakeAccessor.correspondingProperty - dispatchReceiverParameter = fakeAccessor.dispatchReceiverParameter + dispatchReceiverParameter = fakeAccessor.dispatchReceiverParameter?.copyTo(this) } val thisReceiver = JsIrBuilder.buildGetValue(function.dispatchReceiverParameter!!.symbol) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendFunctionsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendFunctionsLowering.kt index 3cfb275b599..1ff9e3f9e09 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendFunctionsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendFunctionsLowering.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.backend.js.lower.coroutines import org.jetbrains.kotlin.backend.common.* import org.jetbrains.kotlin.backend.common.descriptors.* import org.jetbrains.kotlin.backend.common.ir.copyParameterDeclarationsFrom +import org.jetbrains.kotlin.backend.common.ir.copyTo import org.jetbrains.kotlin.backend.common.ir.isSuspend import org.jetbrains.kotlin.backend.common.lower.SymbolWithIrBuilder import org.jetbrains.kotlin.backend.common.lower.createIrBuilder @@ -507,8 +508,10 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo descriptor.bind(declaration) declaration.parent = coroutineClass - declaration.valueParameters += functionParameters.map { - JsIrBuilder.buildValueParameter(it.name, it.index, it.type, it.origin).also { p -> p.parent = declaration } + declaration.valueParameters += functionParameters.mapIndexed { index: Int, parameter: IrValueParameter -> + JsIrBuilder.buildValueParameter(parameter.name, index, parameter.type, parameter.origin).also { p -> + p.parent = declaration + } } declaration.valueParameters += JsIrBuilder.buildValueParameter( completion.name, @@ -637,7 +640,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo descriptor.bind(declaration) declaration.parent = coroutineClass declaration.returnType = coroutineClass.defaultType - declaration.dispatchReceiverParameter = coroutineClassThis + declaration.dispatchReceiverParameter = coroutineClassThis.copyTo(declaration) unboundArgs.mapIndexedTo(declaration.valueParameters) { i, p -> JsIrBuilder.buildValueParameter(p.name, i, p.type, p.origin).also { it.parent = declaration } @@ -656,7 +659,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo declaration.overriddenSymbols += superFunctionDeclaration.symbol } - val thisReceiver = coroutineClassThis + val thisReceiver = declaration.dispatchReceiverParameter!! val irBuilder = context.createIrBuilder(symbol, irFunction.startOffset, irFunction.endOffset) declaration.body = irBuilder.irBlockBody(irFunction.startOffset, irFunction.endOffset) { +irReturn( @@ -726,7 +729,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo val resultSetter = context.coroutineImplResultSymbol.setter!! val exceptionSetter = context.coroutineImplExceptionProperty.setter!! - val thisReceiver = coroutineClassThis + val thisReceiver = declaration.dispatchReceiverParameter!! val irBuilder = context.createIrBuilder(symbol, irFunction.startOffset, irFunction.endOffset) declaration.body = irBuilder.irBlockBody(irFunction.startOffset, irFunction.endOffset) { val dispatchReceiverCall = irCall(createFunction).apply { @@ -806,12 +809,12 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo function.overriddenSymbols += doResumeFunction.symbol function.parent = coroutineClass function.returnType = context.irBuiltIns.anyNType - function.dispatchReceiverParameter = coroutineClassThis + function.dispatchReceiverParameter = coroutineClassThis.copyTo(function) doResumeFunction.valueParameters.mapTo(function.valueParameters) { JsIrBuilder.buildValueParameter(it.name, it.index, it.type, it.origin).also { p -> p.parent = function } } - val thisReceiver = JsIrBuilder.buildGetValue(coroutineClassThis.symbol) + val thisReceiver = JsIrBuilder.buildGetValue(function.dispatchReceiverParameter!!.symbol) suspendResult = JsIrBuilder.buildVar( context.irBuiltIns.anyNType, function,