fix & regression test for GH-3839 (spurious warnings for "when" constructs)

This commit is contained in:
Vern Paxson 2024-07-23 15:18:21 -07:00
parent cb88f6316c
commit e960c29acb
2 changed files with 8 additions and 1 deletions

View file

@ -434,7 +434,7 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const {
// Warn if the function returns something, but we returned from // Warn if the function returns something, but we returned from
// the function without an explicit return, or without a value. // the function without an explicit return, or without a value.
else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID && else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID && ! GetType()->ExpressionlessReturnOkay() &&
(flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) && (flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) &&
! f->HasDelayed() ) ! f->HasDelayed() )
reporter->Warning("non-void function returning without a value: %s", Name()); reporter->Warning("non-void function returning without a value: %s", Name());

View file

@ -26,6 +26,13 @@ event zeek_init()
when [h] ( local hname3 = lookup_addr(h) ) {} when [h] ( local hname3 = lookup_addr(h) ) {}
timeout to + 2sec {} timeout to + 2sec {}
# The following used to generate a spurious warning, so it's here
# as a regression test.
when ( local res = lookup_addr(127.0.0.1) )
{
return;
}
print "done"; print "done";
} }