Improve error messaging for reserved keywords (bug 6199).

This commit is contained in:
David Anderson 2014-07-24 06:51:03 -04:00
parent 6e48ded1a6
commit 97e821dd6f
4 changed files with 15 additions and 2 deletions

View File

@ -3265,12 +3265,18 @@ static int parse_old_decl(declinfo_t *decl, int flags)
strcpy(decl->name, "__unknown__"); strcpy(decl->name, "__unknown__");
} else { } else {
if (!lexpeek(tSYMBOL)) { if (!lexpeek(tSYMBOL)) {
extern char *sc_tokens[];
switch (lextok(&tok)) { switch (lextok(&tok)) {
case tOBJECT: case tOBJECT:
case tCHAR: case tCHAR:
case tVOID: case tVOID:
case tINT: 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; break;
default: default:
lexpush(); lexpush();
@ -3279,7 +3285,7 @@ static int parse_old_decl(declinfo_t *decl, int flags)
} }
if (expecttoken(tSYMBOL, &tok)) if (expecttoken(tSYMBOL, &tok))
strcpy(decl->name, tok.str); strcpy(decl->name, tok.str);
else else if (decl->name[0] == '\0')
strcpy(decl->name, "__unknown__"); strcpy(decl->name, "__unknown__");
} }
} }

View File

@ -200,6 +200,7 @@ static char *errmsg[] = {
/*154*/ "cannot assign INVALID_FUNCTION to a non-function type\n", /*154*/ "cannot assign INVALID_FUNCTION to a non-function type\n",
/*155*/ "expected newline, but found '%s'\n", /*155*/ "expected newline, but found '%s'\n",
/*156*/ "the 'any' type is not allowed in new-style natives\n", /*156*/ "the 'any' type is not allowed in new-style natives\n",
/*157*/ "'%s' is a reserved keyword\n",
#else #else
"\315e\306\230\266k\217:\235\276bu\201fo\220\204\223\012", "\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", "\202l\224\251s\205g\346\356e\233\201(\243\315\215\267\202) \253 f\255low ea\305 \042c\353e\042\012",

View File

@ -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");
}

View File

@ -0,0 +1 @@
(4) : error 157: 'object' is a reserved keyword