diff --git a/src/LuaTransformer.ts b/src/LuaTransformer.ts index e4dab185d..d49fcbe47 100644 --- a/src/LuaTransformer.ts +++ b/src/LuaTransformer.ts @@ -1797,7 +1797,10 @@ export class LuaTransformer { ); } - if (ts.isPropertyAccessExpression(expression.left) || ts.isElementAccessExpression(expression.left)) { + if ( + (ts.isPropertyAccessExpression(expression.left) && !tsHelper.hasSetAccessor(expression.left, this.checker)) + || ts.isElementAccessExpression(expression.left) + ) { // Left is property/element access: cache result while maintaining order of evaluation // (function(o, i, v) o[i] = v; return v end)(${objExpression}, ${indexExpression}, ${right}) const objParameter = tstl.createIdentifier("o"); diff --git a/test/unit/expressions.spec.ts b/test/unit/expressions.spec.ts index c3fd733ae..bb2cfb0bc 100644 --- a/test/unit/expressions.spec.ts +++ b/test/unit/expressions.spec.ts @@ -224,6 +224,7 @@ export class ExpressionTests { @TestCase("inst.field | 3", 8 | 3) @TestCase("inst.field << 3", 8 << 3) @TestCase("inst.field >> 1", 8 >> 1) + @TestCase("inst.field = 3", 7) @TestCase(`"abc" + inst.field`, "abc8") @Test("Get accessor expression") public getAccessorBinary(expression: string, expected: any): void {