Fix compound assignment on arbitrary expression in LHS

(with a convention compound assignment operator defined).
This commit is contained in:
Dmitry Petrov
2016-09-12 16:49:12 +03:00
committed by Dmitry Petrov
parent 0cdf831bf0
commit 3fa33b5969
6 changed files with 70 additions and 4 deletions
@@ -127,7 +127,7 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen
is VariableDescriptor ->
VariableLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor, operator)
else ->
TODO("Other cases of LHS")
OnceExpressionValue(statementGenerator.generateExpression(ktLeft))
}
}
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.psi2ir.generators.CallGenerator
import org.jetbrains.kotlin.types.KotlinType
class OnceExpressionValue(val irExpression: IrExpression) : IntermediateValue {
class OnceExpressionValue(val irExpression: IrExpression) : LValue, AssignmentReceiver {
private var instantiated = false
override fun load(): IrExpression {
@@ -31,4 +31,11 @@ class OnceExpressionValue(val irExpression: IrExpression) : IntermediateValue {
}
override val type: KotlinType get() = irExpression.type
override fun store(irExpression: IrExpression): IrExpression {
throw AssertionError("Expression value ${irExpression.render()} can't be used in store operation")
}
override fun assign(withLValue: (LValue) -> IrExpression): IrExpression =
withLValue(this)
}
@@ -40,8 +40,7 @@ class VariableLValue(
IrGetVariableImpl(startOffset, endOffset, descriptor, irOperator)
override fun store(irExpression: IrExpression): IrExpression =
IrSetVariableImpl(startOffset, endOffset, descriptor,
irExpression, irOperator)
IrSetVariableImpl(startOffset, endOffset, descriptor, irExpression, irOperator)
override fun assign(withLValue: (LValue) -> IrExpression): IrExpression =
withLValue(this)