mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
parse.y: Improve error reporting of type redef
It's happening regularly to me that I forget the type specifier when redef'ing records or enums and usually it takes me a while to figure out what's going on as the errors are not descriptive. Improve the error reporting and just bail as there's no sensible way to continue. Closes #2777
This commit is contained in:
parent
fc0bfd21d5
commit
2f4f01d3f5
8 changed files with 72 additions and 2 deletions
17
src/parse.y
17
src/parse.y
|
@ -1387,9 +1387,22 @@ decl:
|
|||
build_global($2, $3, $4, $5, $6, VAR_CONST);
|
||||
}
|
||||
|
||||
| TOK_REDEF global_id opt_type init_class opt_init opt_attr ';'
|
||||
| TOK_REDEF global_id {
|
||||
if ( $2->IsType() )
|
||||
{
|
||||
auto tag = $2->GetType()->Tag();
|
||||
auto tstr = type_name(tag);
|
||||
if ( tag == TYPE_RECORD || tag == TYPE_ENUM )
|
||||
yyerror(zeek::util::fmt("redef of %s type %s is missing %s keyword",
|
||||
tstr, $2->Name(), tstr));
|
||||
else
|
||||
yyerror(zeek::util::fmt("can not redef %s type %s", tstr, $2->Name()));
|
||||
|
||||
YYERROR; // bail
|
||||
}
|
||||
} opt_type init_class opt_init opt_attr ';'
|
||||
{
|
||||
build_global($2, $3, $4, $5, $6, VAR_REDEF);
|
||||
build_global($2, $4, $5, $6, $7, VAR_REDEF);
|
||||
}
|
||||
|
||||
| TOK_REDEF TOK_ENUM global_id TOK_ADD_TO '{'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue