Merge remote-tracking branch 'origin/topic/jsiwek/gh-1211-improve-already-defined-error' into master

* origin/topic/jsiwek/gh-1211-improve-already-defined-error:
  GH-1211: Improve error message for already-defined functions
This commit is contained in:
Jon Siwek 2020-10-14 10:47:37 -07:00
commit 5f1ee35d31
5 changed files with 23 additions and 2 deletions

View file

@ -1,4 +1,8 @@
3.3.0-dev.426 | 2020-10-14 10:47:37 -0700
* GH-1211: Improve error message for already-defined functions (Jon Siwek, Corelight)
3.3.0-dev.422 | 2020-10-13 16:26:24 -0700
* GH-1208: Use Dictionary validity assertions only during CI (Jon Siwek, Corelight)

View file

@ -1 +1 @@
3.3.0-dev.422
3.3.0-dev.426

View file

@ -583,7 +583,7 @@ void begin_func(IDPtr id, const char* module_name,
case FUNC_FLAVOR_FUNCTION:
if ( ! id->IsRedefinable() )
id->Error("already defined");
id->Error("already defined", t.get());
break;
default:
@ -594,6 +594,10 @@ void begin_func(IDPtr id, const char* module_name,
else
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& 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"); }