mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-1080-error-on-enum-redefinition-conflict'
* origin/topic/jsiwek/gh-1080-error-on-enum-redefinition-conflict: Fix incorrect conflict detection of namespaced-enum-names Improve error message for an enum name conflicting with non-enum ID GH-1080: Treat enum name re-use across different enum types as an error GH-1080: Rename conflicting NetControl::DROP enum definitions Fixes GH-1080
This commit is contained in:
commit
8e99d4b170
14 changed files with 140 additions and 34 deletions
13
src/Type.cc
13
src/Type.cc
|
@ -1248,7 +1248,8 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
|
|||
return;
|
||||
}
|
||||
|
||||
auto id = zeek::detail::lookup_ID(name, module_name.c_str());
|
||||
auto fullname = make_full_var_name(module_name.c_str(), name);
|
||||
auto id = zeek::id::find(fullname);
|
||||
|
||||
if ( ! id )
|
||||
{
|
||||
|
@ -1266,12 +1267,16 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
|
|||
// We allow double-definitions if matching exactly. This is so that
|
||||
// we can define an enum both in a *.bif and *.zeek for avoiding
|
||||
// cyclic dependencies.
|
||||
string fullname = make_full_var_name(module_name.c_str(), name);
|
||||
if ( id->Name() != fullname
|
||||
if ( ! id->IsEnumConst()
|
||||
|| (id->HasVal() && val != id->GetVal()->AsEnum())
|
||||
|| GetName() != id->GetType()->GetName()
|
||||
|| (names.find(fullname) != names.end() && names[fullname] != val) )
|
||||
{
|
||||
zeek::reporter->Error("identifier or enumerator value in enumerated type definition already exists");
|
||||
auto cl = detail::GetCurrentLocation();
|
||||
reporter->PushLocation(&cl, id->GetLocationInfo());
|
||||
reporter->Error("conflicting definition of enum value '%s' in type '%s'",
|
||||
fullname.data(), GetName().data());
|
||||
reporter->PopLocation();
|
||||
SetError();
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue