From b3866d53cdb197080a18d26bb114dd43465d30f1 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 5 Sep 2016 10:13:51 +0300 Subject: [PATCH] Handle arbitrary variable as assignment LHS (e.g., conventional compound assignment for a parameter value). --- .../psi2ir/generators/AssignmentGenerator.kt | 6 ++-- .../expressions/complexAugmentedAssignment.kt | 15 +++++++- .../complexAugmentedAssignment.txt | 36 +++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt index 8cf47c11d4f..3a1c641db45 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt @@ -16,9 +16,7 @@ package org.jetbrains.kotlin.psi2ir.generators -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ConstructorDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression @@ -119,6 +117,8 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen VariableLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor, operator) is PropertyDescriptor -> generateAssignmentReceiverForProperty(descriptor, operator, ktLeft, resolvedCall) + is VariableDescriptor -> + VariableLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor, operator) else -> TODO("Other cases of LHS") } diff --git a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.kt b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.kt index d17173b3b4a..94bae281a8c 100644 --- a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.kt +++ b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.kt @@ -17,4 +17,17 @@ fun test2() { X1.x1++ X1.X2.x2++ X1.X2.X3.x3++ -} \ No newline at end of file +} + +class B(var s: Int = 0) + +object Host { + operator fun B.plusAssign(b: B) { + this.s += b.s + } +} + +fun Host.test3(v: B) { + v += B(1000) +} + diff --git a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt index 81809e4fc81..9d1567f75a6 100644 --- a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt +++ b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt @@ -86,3 +86,39 @@ FILE /complexAugmentedAssignment.kt : CALL .inc type=kotlin.Int operator=POSTFIX_INCR $this: GET_VAR tmp5 type=kotlin.Int operator=null GET_VAR tmp5 type=kotlin.Int operator=null + CLASS CLASS B + CONSTRUCTOR public constructor B(/*0*/ s: kotlin.Int = ...) + s: EXPRESSION_BODY + CONST Int type=kotlin.Int value='0' + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL Any + SET_BACKING_FIELD s type=kotlin.Unit operator=null + GET_VAR s type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + INSTANCE_INITIALIZER_CALL classDescriptor=B + PROPERTY public final var s: kotlin.Int + EXPRESSION_BODY + GET_VAR s type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER + CLASS OBJECT Host + CONSTRUCTOR private constructor Host() + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL Any + INSTANCE_INITIALIZER_CALL classDescriptor=Host + FUN public final operator fun B.plusAssign(/*0*/ b: B): kotlin.Unit + BLOCK_BODY + BLOCK type=kotlin.Unit operator=PLUSEQ + VAR val tmp0_this: B + $RECEIVER of: plusAssign type=B + CALL . type=kotlin.Unit operator=PLUSEQ + $this: GET_VAR tmp0_this type=B operator=null + : CALL .plus type=kotlin.Int operator=PLUSEQ + $this: CALL . type=kotlin.Int operator=PLUSEQ + $this: GET_VAR tmp0_this type=B operator=null + other: CALL . type=kotlin.Int operator=GET_PROPERTY + $this: GET_VAR b type=B operator=null + FUN public fun Host.test3(/*0*/ v: B): kotlin.Unit + BLOCK_BODY + CALL .plusAssign type=kotlin.Unit operator=PLUSEQ + $this: $RECEIVER of: test3 type=Host + $receiver: GET_VAR v type=B operator=PLUSEQ + b: CALL . type=B operator=null + s: CONST Int type=kotlin.Int value='1000'