mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +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);
|
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() )
|
||||||
{
|
{
|
||||||
build_global($2, $3, $4, $5, $6, VAR_REDEF);
|
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, $4, $5, $6, $7, VAR_REDEF);
|
||||||
}
|
}
|
||||||
|
|
||||||
| TOK_REDEF TOK_ENUM global_id TOK_ADD_TO '{'
|
| TOK_REDEF TOK_ENUM global_id TOK_ADD_TO '{'
|
||||||
|
|
2
testing/btest/Baseline/language.redef-missing-type-2/out
Normal file
2
testing/btest/Baseline/language.redef-missing-type-2/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
error in <...>/redef-missing-type.zeek, line 6: redef of enum type Color is missing enum keyword, at or near "Color"
|
2
testing/btest/Baseline/language.redef-missing-type-3/out
Normal file
2
testing/btest/Baseline/language.redef-missing-type-3/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
error in <...>/redef-missing-type.zeek, line 7: redef of enum type Color is missing enum keyword, at or near "Color"
|
2
testing/btest/Baseline/language.redef-missing-type-4/out
Normal file
2
testing/btest/Baseline/language.redef-missing-type-4/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
error in <...>/redef-missing-type.zeek, line 2: syntax error, at or near "count"
|
2
testing/btest/Baseline/language.redef-missing-type-5/out
Normal file
2
testing/btest/Baseline/language.redef-missing-type-5/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
error in <...>/redef-missing-type.zeek, line 2: can not redef table type string_set, at or near "string_set"
|
2
testing/btest/Baseline/language.redef-missing-type-6/out
Normal file
2
testing/btest/Baseline/language.redef-missing-type-6/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
error in <...>/redef-missing-type.zeek, line 3: can not redef vector type sv, at or near "sv"
|
2
testing/btest/Baseline/language.redef-missing-type/out
Normal file
2
testing/btest/Baseline/language.redef-missing-type/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
error in <...>/redef-missing-type.zeek, line 8: redef of record type MyRecord is missing record keyword, at or near "MyRecord"
|
45
testing/btest/language/redef-missing-type.zeek
Normal file
45
testing/btest/language/redef-missing-type.zeek
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>&1
|
||||||
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||||
|
|
||||||
|
type MyRecord: record {
|
||||||
|
s1: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
redef MyRecord += {
|
||||||
|
s2: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
# @TEST-START-NEXT
|
||||||
|
type Color: enum {
|
||||||
|
RED,
|
||||||
|
GREEN,
|
||||||
|
};
|
||||||
|
|
||||||
|
redef Color += {
|
||||||
|
BLUE,
|
||||||
|
};
|
||||||
|
|
||||||
|
# @TEST-START-NEXT
|
||||||
|
type Color: enum {
|
||||||
|
RED,
|
||||||
|
GREEN,
|
||||||
|
};
|
||||||
|
|
||||||
|
# This is very bogus.
|
||||||
|
redef Color: enum += {
|
||||||
|
BLUE,
|
||||||
|
};
|
||||||
|
|
||||||
|
# @TEST-START-NEXT
|
||||||
|
# ...more bogus things.
|
||||||
|
redef count += { 1 };
|
||||||
|
|
||||||
|
# @TEST-START-NEXT
|
||||||
|
# ...more bogus things.
|
||||||
|
redef string_set += { &log };
|
||||||
|
|
||||||
|
# @TEST-START-NEXT
|
||||||
|
# ...also bogus.
|
||||||
|
type sv: vector of string;
|
||||||
|
redef sv += { 1 };
|
Loading…
Add table
Add a link
Reference in a new issue