Fix incorrect conflict detection of namespaced-enum-names

E.g. defining a `Foo::RED` enum name when a `GLOBAL::RED` identifier
already exists would previously be treated as an error, even though the
names don't truly conflict.
This commit is contained in:
Jon Siwek 2020-07-31 16:44:49 -07:00
parent 69c0cf1513
commit 26ad26c101
3 changed files with 9 additions and 6 deletions

View file

@ -1249,7 +1249,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 )
{
@ -1267,9 +1268,7 @@ 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
|| ! id->IsEnumConst()
if ( ! id->IsEnumConst()
|| (id->HasVal() && val != id->GetVal()->AsEnum())
|| GetName() != id->GetType()->GetName()
|| (names.find(fullname) != names.end() && names[fullname] != val) )

View file

@ -1 +1 @@
test::c
a, b, test::a, test::b, test::c

View file

@ -7,4 +7,8 @@ module test;
redef enum foo += { c };
print c;
export {
type foo: enum { a, b };
}
print GLOBAL::a, GLOBAL::b, a, b, c;