mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Emit deprecation warning for use of &deprecated function parameters
Particularly, this is meant for using &deprecated on canonical event/hook prototype parameters to encourage users to create handlers to another, non-deprecated prototype. i.e. for canonical prototypes, we may not always want to put &deprecated directly on the prototype itself since that signals deprecation of the ID entirely.
This commit is contained in:
parent
39f549ed68
commit
26b3d406b4
3 changed files with 42 additions and 1 deletions
10
src/Var.cc
10
src/Var.cc
|
@ -450,7 +450,15 @@ static std::optional<zeek::FuncType::Prototype> func_type_check(const zeek::Func
|
|||
return {};
|
||||
}
|
||||
|
||||
return decl->FindPrototype(*impl->Params());
|
||||
auto rval = decl->FindPrototype(*impl->Params());
|
||||
|
||||
if ( rval )
|
||||
for ( auto i = 0; i < rval->args->NumFields(); ++i )
|
||||
if ( rval->args->FieldDecl(i)->GetAttr(zeek::detail::ATTR_DEPRECATED) )
|
||||
impl->Warn(fmt("use of deprecated parameter '%s'",
|
||||
rval->args->FieldName(i)), decl, true);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
static bool canonical_arg_types_match(const zeek::FuncType* decl, const zeek::FuncType* impl)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
warning in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 9 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 5: use of deprecated parameter 'b' (event(a:string; b:string; c:string;))
|
||||
warning in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 19 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.alternate-prototypes-deprecated-args/alternate-prototypes-deprecated-args.zeek, line 5: use of deprecated prototype (event(a:string; b:string;) and myev)
|
||||
myev (canon), one, two, three
|
||||
myev (new), one, three
|
||||
myev (old), one, two
|
|
@ -0,0 +1,28 @@
|
|||
# @TEST-EXEC: zeek -b %INPUT >out 2>&1
|
||||
#
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||
|
||||
global myev: event(a: string, b: string &deprecated="Don't use 'b'", c: string);
|
||||
global myev: event(a: string, c: string);
|
||||
global myev: event(a: string, b: string) &deprecated="Don't use this prototype";
|
||||
|
||||
event myev(a: string, b: string, c: string) &priority=11
|
||||
{
|
||||
print "myev (canon)", a, b, c;
|
||||
}
|
||||
|
||||
event myev(a: string, c: string) &priority = 7
|
||||
{
|
||||
print "myev (new)", a, c;
|
||||
}
|
||||
|
||||
event myev(a: string, b: string) &priority = 5
|
||||
{
|
||||
print "myev (old)", a, b;
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
event myev("one", "two", "three");
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue