diff --git a/source/ast/InstanceCacheKey.cpp b/source/ast/InstanceCacheKey.cpp index c11facf35..cac64a6d7 100644 --- a/source/ast/InstanceCacheKey.cpp +++ b/source/ast/InstanceCacheKey.cpp @@ -38,7 +38,7 @@ InstanceCacheKey::InstanceCacheKey(const InstanceSymbol& symbol, bool& valid, auto [iface, modport] = conn->getIfaceConn(); while (iface && iface->kind == SymbolKind::InstanceArray) { auto& arr = iface->as(); - if (arr.empty()) + if (arr.elements.empty()) iface = nullptr; else iface = arr.elements[0]; diff --git a/tests/unittests/ast/InterfaceTests.cpp b/tests/unittests/ast/InterfaceTests.cpp index c9a05fd70..62728e017 100644 --- a/tests/unittests/ast/InterfaceTests.cpp +++ b/tests/unittests/ast/InterfaceTests.cpp @@ -940,3 +940,37 @@ endmodule REQUIRE(diags.size() == 1); CHECK(diags[0].code == diag::VirtualInterfaceIfaceMember); } + +TEST_CASE("Arrayed interface port cache regress -- GH #1947") { + // NoAck has no 'ack', so on_no_ack is in error. It is written second because that is + // the instance a shared body would hide. + auto tree = SyntaxTree::fromText(R"( +interface HasAck; + logic req; + logic ack; +endinterface + +interface NoAck; + logic req; +endinterface + +module Reader (interface a[2]); + initial $display("%b", a[0].ack); +endmodule + +module top; + HasAck has_ack [2] (); + NoAck no_ack [2] (); + + Reader on_has_ack (.a(has_ack)); + Reader on_no_ack (.a(no_ack)); +endmodule +)"); + + Compilation compilation; + compilation.addSyntaxTree(tree); + + auto& diags = compilation.getAllDiagnostics(); + REQUIRE(diags.size() == 1); + CHECK(diags[0].code == diag::CouldNotResolveHierarchicalPath); +}