Skip to content

Commit 6293b10

Browse files
committed
Compile incrementors within the initializer's flow in for loops
It turns out that incrementors were compiled with the body's flow, which meant that the incrementor had access to local variables declared in the body. Now, incrementors no longer have access to such variables. Fixes AssemblyScript#2825.
1 parent de174c5 commit 6293b10

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Diff for: src/compiler.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2600,6 +2600,7 @@ export class Compiler extends DiagnosticEmitter {
26002600
if (possiblyLoops) {
26012601
let incrementor = statement.incrementor;
26022602
if (incrementor) {
2603+
this.currentFlow = flow;
26032604
bodyStmts.push(
26042605
this.compileExpression(incrementor, Type.void, Constraints.ConvImplicit | Constraints.WillDrop)
26052606
);

Diff for: tests/compiler/issues/2826.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"stderr": [
3+
"TS2304: Cannot find name 'j'."
4+
]
5+
}

Diff for: tests/compiler/issues/2826.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
for (let i = 0; i < 2; j++) {
2+
let j = 0;
3+
}

0 commit comments

Comments
 (0)