@@ -5,11 +5,14 @@ import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
5
5
import org.jetbrains.kotlin.backend.jvm.ir.fileParent
6
6
import org.jetbrains.kotlin.descriptors.ClassKind
7
7
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
8
+ import org.jetbrains.kotlin.descriptors.Modality
8
9
import org.jetbrains.kotlin.ir.builders.*
9
10
import org.jetbrains.kotlin.ir.builders.declarations.*
10
11
import org.jetbrains.kotlin.ir.declarations.*
11
12
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
13
+ import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
12
14
import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
15
+ import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
13
16
import org.jetbrains.kotlin.ir.types.IrSimpleType
14
17
import org.jetbrains.kotlin.ir.types.getClass
15
18
import org.jetbrains.kotlin.ir.types.typeOrNull
@@ -146,22 +149,39 @@ fun IrPluginContext.createSuspendLambdaFunctionWithCoroutineScope(
146
149
function : IrFunction ,
147
150
blockBodyBuilder : IrBlockBodyBuilder
148
151
): IrSimpleFunction {
149
- val func = IrFactoryImpl .buildFun {
150
- name = SpecialNames .NO_NAME_PROVIDED
151
- visibility = DescriptorVisibilities .LOCAL
152
- isSuspend = true
153
- returnType = function.returnType
154
- }
152
+ val func = IrFunctionImpl (
153
+ startOffset = - 1 ,
154
+ endOffset = - 1 ,
155
+ origin = IrDeclarationOrigin .LOCAL_FUNCTION_FOR_LAMBDA ,
156
+ name = SpecialNames .NO_NAME_PROVIDED ,
157
+ visibility = DescriptorVisibilities .LOCAL ,
158
+ isInline = false ,
159
+ isExpect = false ,
160
+ returnType = function.returnType,
161
+ modality = Modality .FINAL ,
162
+ symbol = IrSimpleFunctionSymbolImpl (),
163
+ isSuspend = true ,
164
+ isTailrec = false ,
165
+ isOperator = false ,
166
+ isInfix = false ,
167
+ isExternal = false ,
168
+ )
169
+
170
+ // val func1 = IrFactoryImpl.buildFun {
171
+ // name = SpecialNames.NO_NAME_PROVIDED
172
+ // visibility = DescriptorVisibilities.LOCAL
173
+ // isSuspend = true
174
+ // returnType = function.returnType
175
+ // }
155
176
156
177
with (func) {
157
178
parent = function
158
- origin = IrDeclarationOrigin .LOCAL_FUNCTION_FOR_LAMBDA
159
-
179
+ // origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
160
180
161
181
body = createIrBuilder(symbol).run {
162
182
// don't use expr body, coroutine codegen can't generate for it.
163
183
irBlockBody {
164
- + irCall(originFunction).apply call@{
184
+ + irReturn( irCall(originFunction).apply call@{
165
185
// set arguments
166
186
function.dispatchReceiverParameter?.also {
167
187
this @call.dispatchReceiver = irGet(it)
@@ -174,7 +194,7 @@ fun IrPluginContext.createSuspendLambdaFunctionWithCoroutineScope(
174
194
for ((index, parameter) in function.valueParameters.withIndex()) {
175
195
this @call.putValueArgument(index, irGet(parameter))
176
196
}
177
- }
197
+ })
178
198
}
179
199
}
180
200
}
0 commit comments