mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
GH-1080: Treat enum name re-use across different enum types as an error
This commit is contained in:
parent
613b27eec7
commit
4a9567e04f
3 changed files with 44 additions and 1 deletions
|
@ -1270,9 +1270,14 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
|
||||||
string fullname = make_full_var_name(module_name.c_str(), name);
|
string fullname = make_full_var_name(module_name.c_str(), name);
|
||||||
if ( id->Name() != fullname
|
if ( id->Name() != fullname
|
||||||
|| (id->HasVal() && val != id->GetVal()->AsEnum())
|
|| (id->HasVal() && val != id->GetVal()->AsEnum())
|
||||||
|
|| GetName() != id->GetType()->GetName()
|
||||||
|| (names.find(fullname) != names.end() && names[fullname] != val) )
|
|| (names.find(fullname) != names.end() && names[fullname] != val) )
|
||||||
{
|
{
|
||||||
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();
|
SetError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 10 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 6: conflicting definition of enum value 'BLUE' in type 'b'
|
||||||
|
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 15 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 5: conflicting definition of enum value 'RED' in type 'b'
|
||||||
|
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 27 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 23: conflicting definition of enum value 'Foo::TWO' in type 'Foo::bf'
|
||||||
|
error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 32 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.enum-name-conflict/enum-name-conflict.zeek, line 22: conflicting definition of enum value 'Foo::ONE' in type 'Foo::bf'
|
34
testing/btest/language/enum-name-conflict.zeek
Normal file
34
testing/btest/language/enum-name-conflict.zeek
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# @TEST-EXEC-FAIL: zeek -b %INPUT >output 2>&1
|
||||||
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath" btest-diff output
|
||||||
|
|
||||||
|
type a: enum {
|
||||||
|
RED,
|
||||||
|
BLUE
|
||||||
|
};
|
||||||
|
|
||||||
|
type b: enum {
|
||||||
|
BLUE,
|
||||||
|
GREEN
|
||||||
|
};
|
||||||
|
|
||||||
|
redef enum b += {
|
||||||
|
RED,
|
||||||
|
};
|
||||||
|
|
||||||
|
module Foo;
|
||||||
|
|
||||||
|
export {
|
||||||
|
type af: enum {
|
||||||
|
ONE,
|
||||||
|
TWO
|
||||||
|
};
|
||||||
|
|
||||||
|
type bf: enum {
|
||||||
|
TWO,
|
||||||
|
THREE
|
||||||
|
};
|
||||||
|
|
||||||
|
redef enum bf += {
|
||||||
|
ONE,
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue