Merge remote-tracking branch 'origin/topic/bbannier/issue-3279'

* origin/topic/bbannier/issue-3279:
  Fix handling of module scope when checking exported Spicy types for collisions

(cherry picked from commit 30dc6af831)
This commit is contained in:
Arne Welzel 2023-09-15 11:57:04 +02:00 committed by Tim Wojtulewicz
parent b6090f1fe6
commit 651b208937
2 changed files with 21 additions and 1 deletions

View file

@ -215,7 +215,7 @@ void Manager::registerPacketAnalyzer(const std::string& name, const std::string&
void Manager::registerType(const std::string& id, const TypePtr& type) { void Manager::registerType(const std::string& id, const TypePtr& type) {
auto [ns, local] = parseID(id); auto [ns, local] = parseID(id);
if ( const auto& old = detail::lookup_ID(local.c_str(), ns.c_str()) ) { if ( const auto& old = detail::lookup_ID(local.c_str(), ns.c_str(), true) ) {
// This is most likely to trigger for IDs that other Spicy modules // This is most likely to trigger for IDs that other Spicy modules
// register. If we two Spicy modules need the same type, that's ok as // register. If we two Spicy modules need the same type, that's ok as
// long as they match. // long as they match.

View file

@ -0,0 +1,20 @@
# @TEST-REQUIRES: have-spicy
#
# @TEST-EXEC: spicyz -d -o foo.hlto foo.spicy foo.evt
# @TEST-EXEC: zeek -NN Zeek::Spicy foo.hlto >output1 2>&1
# @TEST-EXEC: ZEEK_SPICY_MODULE_PATH=$PWD zeek -B all -NN Zeek::Spicy >output2 2>&1
# @TEST-EXEC: diff output1 output2 1>&2
#
# @TEST-DOC: This validates that an exported Spicy name with local part identical with a Zeek name in global scope does not clash. Regression test for #3279.
# @TEST-START-FILE foo.spicy
module foo;
# `foo::Direction` has the same local part as Zeek's `::Direction`.
public type Direction = enum { a };
public type Other = enum { a };
# @TEST-END-FILE
# @TEST-START-FILE foo.evt
import foo;
# @TEST-END-FILE