Emit error for alternate event/hook prototype args with attributes

Argument attributes are only allowed in the canonical prototype.
This commit is contained in:
Jon Siwek 2020-04-09 21:00:09 -07:00
parent 9b6934eab8
commit 070b28ac05
4 changed files with 64 additions and 0 deletions

View file

@ -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 )

View file

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

View file

@ -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

View file

@ -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