Skip to content

Commit

Permalink
Merge pull request #111 from alliedmodders/bug6199
Browse files Browse the repository at this point in the history
Improve error messaging for reserved keywords (bug 6199).
  • Loading branch information
dvander committed Jul 24, 2014
2 parents 6e48ded + 97e821d commit abcd106
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sourcepawn/compiler/sc1.c
Expand Up @@ -3265,12 +3265,18 @@ static int parse_old_decl(declinfo_t *decl, int flags)
strcpy(decl->name, "__unknown__");
} else {
if (!lexpeek(tSYMBOL)) {
extern char *sc_tokens[];
switch (lextok(&tok)) {
case tOBJECT:
case tCHAR:
case tVOID:
case tINT:
error(143);
if (lexpeek(tSYMBOL)) {
error(143);
} else {
error(157, sc_tokens[tok.id - tFIRST]);
strcpy(decl->name, sc_tokens[tok.id - tFIRST]);
}
break;
default:
lexpush();
Expand All @@ -3279,7 +3285,7 @@ static int parse_old_decl(declinfo_t *decl, int flags)
}
if (expecttoken(tSYMBOL, &tok))
strcpy(decl->name, tok.str);
else
else if (decl->name[0] == '\0')
strcpy(decl->name, "__unknown__");
}
}
Expand Down
1 change: 1 addition & 0 deletions sourcepawn/compiler/sc5.scp
Expand Up @@ -200,6 +200,7 @@ static char *errmsg[] = {
/*154*/ "cannot assign INVALID_FUNCTION to a non-function type\n",
/*155*/ "expected newline, but found '%s'\n",
/*156*/ "the 'any' type is not allowed in new-style natives\n",
/*157*/ "'%s' is a reserved keyword\n",
#else
"\315e\306\230\266k\217:\235\276bu\201fo\220\204\223\012",
"\202l\224\251s\205g\346\356e\233\201(\243\315\215\267\202) \253 f\255low ea\305 \042c\353e\042\012",
Expand Down
5 changes: 5 additions & 0 deletions sourcepawn/compiler/tests/fail-object-keyword-as-name.sp
@@ -0,0 +1,5 @@
public Action:SomeEvent( Handle:event, const String:name[], bool:dontBroadcast)
{
// error 143: new-style declarations should not have "new"
new object = GetEventInt(event, "object");
}
1 change: 1 addition & 0 deletions sourcepawn/compiler/tests/fail-object-keyword-as-name.txt
@@ -0,0 +1 @@
(4) : error 157: 'object' is a reserved keyword

0 comments on commit abcd106

Please sign in to comment.