fix bug where variable=0 initializer was forgotten if vardecl is followed by an augmented assignment

This commit is contained in:
Irmen de Jong 2021-11-17 22:31:43 +01:00
parent 6af3209d4d
commit 2e0450d7ed

View File

@ -59,8 +59,10 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport
val nextAssign = nextStmt as? Assignment val nextAssign = nextStmt as? Assignment
val nextFor = nextStmt as? ForLoop val nextFor = nextStmt as? ForLoop
val hasNextForWithThisLoopvar = nextFor?.loopVar?.nameInSource==listOf(decl.name) val hasNextForWithThisLoopvar = nextFor?.loopVar?.nameInSource==listOf(decl.name)
val hasNextAssignment = nextAssign!=null && nextAssign.target isSameAs IdentifierReference(listOf(decl.name), Position.DUMMY) val hasNextAssignmentThatAlsoInitializes = nextAssign!=null
if (!hasNextAssignment && !hasNextForWithThisLoopvar) { && nextAssign.target isSameAs IdentifierReference(listOf(decl.name), Position.DUMMY)
&& !nextAssign.isAugmentable
if (!hasNextAssignmentThatAlsoInitializes && !hasNextForWithThisLoopvar) {
// Add assignment to initialize with zero // 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. // 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) val identifier = IdentifierReference(listOf(decl.name), decl.position)