Merge pull request #5448 from Vexu/translate-c

Translate-c use correct scope in for loop condition
This commit is contained in:
Veikka Tuominen
2020-05-27 17:00:31 +03:00
committed by GitHub
2 changed files with 14 additions and 1 deletions

View File

@@ -2515,7 +2515,7 @@ fn transForLoop(
}
var cond_scope = Scope.Condition{
.base = .{
.parent = scope,
.parent = &loop_scope,
.id = .Condition,
},
};

View File

@@ -256,4 +256,17 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
\\ return 0;
\\}
, "");
cases.add("scoped for loops with shadowing",
\\#include <stdlib.h>
\\int main() {
\\ int count = 0;
\\ for (int x = 0; x < 2; x++)
\\ for (int x = 0; x < 2; x++)
\\ count++;
\\
\\ if (count != 4) abort();
\\ return 0;
\\}
,"");
}