diff --git a/src/ID.cc b/src/ID.cc index 0031d833bc..10719cdaca 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -481,6 +481,10 @@ void ID::DescribeReST(ODesc* d, bool roles_only) const { } if ( val && type && type->Tag() != TYPE_FUNC && type->InternalType() != TYPE_INTERNAL_VOID && + // Do not include a default value for enum const identifiers, + // as their value can't be changed. + ! IsEnumConst() && + // Values within Version module are likely to include a // constantly-changing version number and be a frequent // source of error/desynchronization, so don't include them. diff --git a/src/Type.cc b/src/Type.cc index a5d57d187c..451bb9934e 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1567,7 +1567,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek if ( deprecation ) id->MakeDeprecated({NewRef{}, deprecation}); - detail::zeekygen_mgr->Identifier(std::move(id), from_redef); + detail::zeekygen_mgr->Identifier(id, from_redef); } else { // We allow double-definitions if matching exactly. This is so that @@ -1591,6 +1591,12 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, zeek if ( vals.find(val) == vals.end() ) vals[val] = make_intrusive(IntrusivePtr{NewRef{}, this}, val); + if ( ! id->HasVal() ) + id->SetVal(vals[val]); + else if ( id->GetVal()->AsEnum() != val ) + reporter->InternalError("inconsistent enum integer value for '%s' (old %" PRId64 " new %" PRId64 ")", + fullname.c_str(), id->GetVal()->AsEnum(), val); + const auto& types = Type::Aliases(GetName()); for ( const auto& t : types )