KT-16566 Support destructuring declarations for lambda parameter in psi2ir
This commit is contained in:
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.psi2ir.intermediate.VariableLValue
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
||||
@@ -71,6 +72,15 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
|
||||
|
||||
val ktBody = ktFun.bodyExpression!!
|
||||
val irBlockBody = IrBlockBodyImpl(ktBody.startOffset, ktBody.endOffset)
|
||||
|
||||
for (ktParameter in ktFun.valueParameters) {
|
||||
val ktDestructuringDeclaration = ktParameter.destructuringDeclaration ?: continue
|
||||
val valueParameter = getOrFail(BindingContext.VALUE_PARAMETER, ktParameter)
|
||||
val parameterValue = VariableLValue(ktDestructuringDeclaration.startOffset, ktDestructuringDeclaration.endOffset,
|
||||
valueParameter, IrStatementOrigin.DESTRUCTURING_DECLARATION)
|
||||
statementGenerator.declareComponentVariablesInBlock(ktDestructuringDeclaration, irBlockBody, parameterValue)
|
||||
}
|
||||
|
||||
if (ktBody is KtBlockExpression) {
|
||||
val ktBodyStatements = ktBody.statements
|
||||
if (ktBodyStatements.isNotEmpty()) {
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ class StatementGenerator(
|
||||
return irBlock
|
||||
}
|
||||
|
||||
fun declareComponentVariablesInBlock(multiDeclaration: KtDestructuringDeclaration, irBlock: IrContainerExpressionBase, containerValue: IntermediateValue) {
|
||||
fun declareComponentVariablesInBlock(multiDeclaration: KtDestructuringDeclaration, irBlock: IrStatementContainer, containerValue: IntermediateValue) {
|
||||
val callGenerator = CallGenerator(this)
|
||||
for ((index, ktEntry) in multiDeclaration.entries.withIndex()) {
|
||||
val componentResolvedCall = getOrFail(BindingContext.COMPONENT_RESOLVED_CALL, ktEntry)
|
||||
|
||||
Reference in New Issue
Block a user