diff --git a/sourcepawn/compiler/sc1.cpp b/sourcepawn/compiler/sc1.cpp index 0cc07861..0db9c615 100644 --- a/sourcepawn/compiler/sc1.cpp +++ b/sourcepawn/compiler/sc1.cpp @@ -1445,12 +1445,25 @@ static void dodecl(const token_t *tok) return; } - int fpublic = (tok->id == tPUBLIC); - int fstock = (tok->id == tSTOCK); - int fstatic = (tok->id == tSTATIC); + int fpublic = FALSE, fstock = FALSE, fstatic = FALSE, fconst = FALSE; + switch (tok->id) { + case tPUBLIC: + fpublic = TRUE; + break; + case tSTOCK: + fstock = TRUE; + if (matchtoken(tSTATIC)) + fstatic = TRUE; + break; + case tSTATIC: + fstatic = TRUE; - if (fstatic && matchtoken(tSTOCK)) - fstock = TRUE; + // For compatibility, we must include this case. Though "stock" should + // come first. + if (matchtoken(tSTOCK)) + fstock = TRUE; + break; + } int flags = DECLFLAG_MAYBE_FUNCTION | DECLFLAG_VARIABLE | DECLFLAG_ENUMROOT; if (tok->id == tNEW) @@ -1462,7 +1475,13 @@ static void dodecl(const token_t *tok) decl.type.tag = 0; } - if (!decl.opertok && (tok->id == tNEW || decl.type.has_postdims || !lexpeek('('))) { + // Hacky bag o' hints as to whether this is a variable decl. + bool probablyVariable = tok->id == tNEW || + decl.type.has_postdims || + !lexpeek('(') || + ((decl.type.usage & uCONST) == uCONST); + + if (!decl.opertok && probablyVariable) { if (tok->id == tNEW && decl.type.is_new) error(143); if (decl.type.tag & STRUCTTAG) { diff --git a/sourcepawn/compiler/tests/ok-static-stocks-1.sp b/sourcepawn/compiler/tests/ok-static-stocks-1.sp new file mode 100644 index 00000000..bf523238 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-static-stocks-1.sp @@ -0,0 +1,5 @@ +static stock const X = 5; +stock static const Y = 6; + +public main() +{} diff --git a/sourcepawn/compiler/tests/ok-static-stocks-2.sp b/sourcepawn/compiler/tests/ok-static-stocks-2.sp new file mode 100644 index 00000000..2ced8743 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-static-stocks-2.sp @@ -0,0 +1,7 @@ +static stock const X = 5; +stock static const Y = 6; + +public main() +{ + return X + Y; +}