authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-27 17:00:31+03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-05-27 17:00:31+03:00
log2ae9e06363b294f60b62e765d31fce4417e14a9d
tree2490713f0d933708c4e7b7fd0eaa48af141cba39
parente61e8c94beba912400b71891d8bfcfa9c1c1d837
parentcd5b7b9e1d56b22bc2267d5d94acec8d21c29110
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #5448 from Vexu/translate-c

Translate-c use correct scope in for loop condition

2 files changed, 14 insertions(+), 1 deletions(-)

src-self-hosted/translate_c.zig+1-1
...@@ -2515,7 +2515,7 @@ fn transForLoop(...@@ -2515,7 +2515,7 @@ fn transForLoop(
2515 }2515 }
2516 var cond_scope = Scope.Condition{2516 var cond_scope = Scope.Condition{
2517 .base = .{2517 .base = .{
2518 .parent = scope,2518 .parent = &loop_scope,
2519 .id = .Condition,2519 .id = .Condition,
2520 },2520 },
2521 };2521 };
test/run_translated_c.zig+13
...@@ -256,4 +256,17 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {...@@ -256,4 +256,17 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
256 \\ return 0;256 \\ return 0;
257 \\}257 \\}
258 , "");258 , "");
259
260 cases.add("scoped for loops with shadowing",
261 \\#include <stdlib.h>
262 \\int main() {
263 \\ int count = 0;
264 \\ for (int x = 0; x < 2; x++)
265 \\ for (int x = 0; x < 2; x++)
266 \\ count++;
267 \\
268 \\ if (count != 4) abort();
269 \\ return 0;
270 \\}
271 ,"");
259}272}