From 2e0450d7edb31abd0e0620854da4f48594fb682d Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 17 Nov 2021 22:31:43 +0100 Subject: [PATCH] fix bug where variable=0 initializer was forgotten if vardecl is followed by an augmented assignment --- .../src/prog8/compiler/astprocessing/StatementReorderer.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt index b8b85c402..0486d2c79 100644 --- a/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt +++ b/compiler/src/prog8/compiler/astprocessing/StatementReorderer.kt @@ -59,8 +59,10 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport val nextAssign = nextStmt as? Assignment val nextFor = nextStmt as? ForLoop val hasNextForWithThisLoopvar = nextFor?.loopVar?.nameInSource==listOf(decl.name) - val hasNextAssignment = nextAssign!=null && nextAssign.target isSameAs IdentifierReference(listOf(decl.name), Position.DUMMY) - if (!hasNextAssignment && !hasNextForWithThisLoopvar) { + val hasNextAssignmentThatAlsoInitializes = nextAssign!=null + && nextAssign.target isSameAs IdentifierReference(listOf(decl.name), Position.DUMMY) + && !nextAssign.isAugmentable + if (!hasNextAssignmentThatAlsoInitializes && !hasNextForWithThisLoopvar) { // Add assignment to initialize with zero // Note: for block-level vars, this will introduce assignments in the block scope. These have to be dealt with correctly later. val identifier = IdentifierReference(listOf(decl.name), decl.position)