From cb47b322635e68c77c483f45f809dccf45205126 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Thu, 14 Jan 2016 18:09:45 -0800 Subject: [PATCH] Be smarter about marking locals as mutable --- ast/typeChecker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ast/typeChecker.ts b/ast/typeChecker.ts index 4f4fe6e9..e205e7f6 100644 --- a/ast/typeChecker.ts +++ b/ast/typeChecker.ts @@ -1656,7 +1656,6 @@ module TDev.AST } } else { var loc = thing; - loc._isMutable = true; if (this.readOnlyLocals.indexOf(loc) >= 0) { if (!AST.writableLocalsInClosures && this.actionSection == ActionSection.Lambda) { this.markError(trg, lf("TD107: inline functions cannot assign to locals from outside like '{0}'", name)); @@ -1668,6 +1667,10 @@ module TDev.AST loc._isCaptured = true; this.recordLocalWrite(loc) } + + // if it wasn't captured yet anywhere, and we're not inside a loop, no reason to treat it as mutable just yet + if (loc._isCaptured || this.currLoop) + loc._isMutable = true; } this.typeCheckExpr(trg); } else {