GH-1211: Improve error message for already-defined functions

This commit is contained in:
Jon Siwek 2020-10-12 16:19:19 -07:00
parent b73cc816e9
commit 8c85f2135e
3 changed files with 18 additions and 1 deletions

View file

@ -583,7 +583,7 @@ void begin_func(IDPtr id, const char* module_name,
case FUNC_FLAVOR_FUNCTION: case FUNC_FLAVOR_FUNCTION:
if ( ! id->IsRedefinable() ) if ( ! id->IsRedefinable() )
id->Error("already defined"); id->Error("already defined", t.get());
break; break;
default: default:
@ -594,6 +594,10 @@ void begin_func(IDPtr id, const char* module_name,
else else
id->SetType(t); id->SetType(t);
if ( IsErrorType(id->GetType()->Tag()) )
reporter->FatalError("invalid definition of '%s' (see previous errors)",
id->Name());
const auto& args = t->Params(); const auto& args = t->Params();
const auto& canon_args = id->GetType()->AsFuncType()->Params(); const auto& canon_args = id->GetType()->AsFuncType()->Params();

View file

@ -0,0 +1,2 @@
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.function-already-defined/function-already-defined.zeek, line 4 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.function-already-defined/function-already-defined.zeek, line 7: already defined (foo)
fatal error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.function-already-defined/function-already-defined.zeek, line 8: invalid definition of 'foo' (see previous errors)

View file

@ -0,0 +1,11 @@
# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
function foo(a: string)
{ print a; }
function foo(a: string)
{ }
event zeek_init()
{ foo("hello"); }