mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Emit error for alternate event/hook prototype args with attributes
Argument attributes are only allowed in the canonical prototype.
This commit is contained in:
parent
9b6934eab8
commit
070b28ac05
4 changed files with 64 additions and 0 deletions
|
@ -76,6 +76,13 @@ static bool add_prototype(ID* id, BroType* t, attr_list* attrs,
|
|||
for ( auto i = 0; i < alt_args->NumFields(); ++i )
|
||||
{
|
||||
auto field = alt_args->FieldName(i);
|
||||
|
||||
if ( alt_args->FieldDecl(i)->attrs )
|
||||
{
|
||||
alt_ft->Error(fmt("alternate function prototype arguments may not have attributes: arg '%s'", field), canon_ft);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto o = canon_args->FieldOffset(field);
|
||||
|
||||
if ( o < 0 )
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
error in ./bad.zeek, line 2 and ./bad.zeek, line 1: alternate function prototype arguments may not have attributes: arg 'a' (event(c:string; b:string; a:string;) and event(a:string; b:string; c:string;))
|
|
@ -0,0 +1,6 @@
|
|||
foo, A, B, C
|
||||
foo, A, B, C
|
||||
reverse foo, A, B, C
|
||||
foo a, A
|
||||
foo b, B
|
||||
foo c, C
|
|
@ -0,0 +1,50 @@
|
|||
# @TEST-EXEC: zeek -b %INPUT >out
|
||||
# @TEST-EXEC-FAIL: zeek -b bad.zeek >errors 2>&1
|
||||
# @TEST-EXEC: btest-diff out
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff errors
|
||||
|
||||
global foo: event(a: string, b: string, c: string &default="C");
|
||||
global foo: event(c: string, b: string, a: string);
|
||||
global foo: event(a: string);
|
||||
global foo: event(b: string);
|
||||
global foo: event(c: string);
|
||||
|
||||
event foo(a: string, b: string, c: string)
|
||||
{
|
||||
print "foo", a, b, c;
|
||||
}
|
||||
|
||||
event foo(mya: string, b: string, c: string)
|
||||
{
|
||||
print "foo", mya, b, c;
|
||||
}
|
||||
|
||||
event foo(c: string, b: string, a: string)
|
||||
{
|
||||
print "reverse foo", a, b, c;
|
||||
}
|
||||
|
||||
event foo(a: string)
|
||||
{
|
||||
print "foo a", a;
|
||||
}
|
||||
|
||||
event foo(b: string)
|
||||
{
|
||||
print "foo b", b;
|
||||
}
|
||||
|
||||
event foo(c: string)
|
||||
{
|
||||
print "foo c", c;
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
event foo("A", "B");
|
||||
}
|
||||
|
||||
@TEST-START-FILE bad.zeek
|
||||
global foo: event(a: string, b: string, c: string &default="C");
|
||||
global foo: event(c: string, b: string, a: string &default="A");
|
||||
@TEST-END-FILE bad.zeek
|
Loading…
Add table
Add a link
Reference in a new issue