From bfc65b086a6731ce76f728a92cbc5a5555412ba3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 5 Jul 2014 00:48:32 -0700 Subject: [PATCH] Fix bug in newdecls in for loop initializers. --- sourcepawn/compiler/sc1.c | 22 +++++++++++++++++++++ sourcepawn/compiler/tests/ok-for-newdecl.sp | 5 +++++ 2 files changed, 27 insertions(+) create mode 100644 sourcepawn/compiler/tests/ok-for-newdecl.sp diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index c7cf1ca7..f12ac7d0 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -6965,6 +6965,28 @@ static int dofor(void) autozero=1; declloc(tok.id); /* declare local variable */ break; + case tSYMBOL: + { + // See comment in statement() near tSYMBOL. + int is_decl = FALSE; + if (matchtoken('[')) { + if (lexpeek(']')) + is_decl = TRUE; + lexpush(); + } else if (lexpeek(tSYMBOL)) { + is_decl = TRUE; + } + + if (is_decl) { + lexpush(); + nestlevel++; + autozero=1; + declloc(tSYMBOL); + break; + } + + // Fall-through to default! + } default: lexpush(); doexpr(TRUE,TRUE,TRUE,TRUE,NULL,NULL,FALSE); /* expression 1 */ diff --git a/sourcepawn/compiler/tests/ok-for-newdecl.sp b/sourcepawn/compiler/tests/ok-for-newdecl.sp new file mode 100644 index 00000000..575151d2 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-for-newdecl.sp @@ -0,0 +1,5 @@ +public OnPluginStart() +{ + for (bool x; x;) { + } +}