mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
GH-1741: Print error if calling a non-hook with hook keyword
This commit is contained in:
parent
c15a9eab7f
commit
b966a3876f
3 changed files with 20 additions and 9 deletions
|
@ -721,8 +721,12 @@ expr:
|
||||||
{
|
{
|
||||||
--in_hook;
|
--in_hook;
|
||||||
set_location(@1, @3);
|
set_location(@1, @3);
|
||||||
|
|
||||||
if ( $3->Tag() != EXPR_CALL )
|
if ( $3->Tag() != EXPR_CALL )
|
||||||
$3->Error("not a valid hook call expression");
|
$3->Error("not a valid hook call expression");
|
||||||
|
else if ( $3->AsCallExpr()->Func()->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_HOOK )
|
||||||
|
$3->Error("hook keyword should only be used to call hooks");
|
||||||
|
|
||||||
$$ = $3;
|
$$ = $3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
error in ./invalid.zeek, line 9: hook cannot be called directly, use hook operator (myhook)
|
error in ./invalid.zeek, line 14: hook cannot be called directly, use hook operator (myhook)
|
||||||
error in ./invalid.zeek, line 10: hook cannot be called directly, use hook operator (myhook)
|
error in ./invalid.zeek, line 15: hook cannot be called directly, use hook operator (myhook)
|
||||||
error in ./invalid.zeek, line 11: hook cannot be called directly, use hook operator (myhook)
|
error in ./invalid.zeek, line 16: hook cannot be called directly, use hook operator (myhook)
|
||||||
error in ./invalid.zeek, line 12: not a valid hook call expression (2 + 2)
|
error in ./invalid.zeek, line 17: not a valid hook call expression (2 + 2)
|
||||||
warning in ./invalid.zeek, line 12: expression value ignored (2 + 2)
|
warning in ./invalid.zeek, line 17: expression value ignored (2 + 2)
|
||||||
error in ./invalid.zeek, line 13: not a valid hook call expression (2 + 2)
|
error in ./invalid.zeek, line 18: not a valid hook call expression (2 + 2)
|
||||||
error in ./invalid.zeek, line 15: hook cannot be called directly, use hook operator (h)
|
error in ./invalid.zeek, line 20: hook cannot be called directly, use hook operator (h)
|
||||||
error in ./invalid.zeek, line 16: hook cannot be called directly, use hook operator (h)
|
error in ./invalid.zeek, line 21: hook cannot be called directly, use hook operator (h)
|
||||||
|
error in ./invalid.zeek, line 24: hook keyword should only be used to call hooks (foo())
|
||||||
|
|
|
@ -15,7 +15,7 @@ hook myhook(i: count)
|
||||||
hook myhook(i: count) &priority=-1
|
hook myhook(i: count) &priority=-1
|
||||||
{
|
{
|
||||||
print "other myhook()", i;
|
print "other myhook()", i;
|
||||||
}
|
}
|
||||||
|
|
||||||
function indirect(): hook(i: count)
|
function indirect(): hook(i: count)
|
||||||
{
|
{
|
||||||
|
@ -66,6 +66,11 @@ hook myhook(i: count)
|
||||||
if ( i == 0 ) break;
|
if ( i == 0 ) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function foo()
|
||||||
|
{
|
||||||
|
print "foo()";
|
||||||
|
}
|
||||||
|
|
||||||
event zeek_init()
|
event zeek_init()
|
||||||
{
|
{
|
||||||
myhook(3);
|
myhook(3);
|
||||||
|
@ -78,5 +83,6 @@ event zeek_init()
|
||||||
if ( h(3) )
|
if ( h(3) )
|
||||||
print "hmm";
|
print "hmm";
|
||||||
print "done";
|
print "done";
|
||||||
|
hook foo();
|
||||||
}
|
}
|
||||||
@TEST-END-FILE
|
@TEST-END-FILE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue