From 1010137a2096e90f5706c47c566c526912554265 Mon Sep 17 00:00:00 2001 From: micron-ian <133904139+micron-ian@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:21:17 -0600 Subject: [PATCH] Fix bad assignment for virtual interface element select by reversing the order of the selectors so that we encounter element select syntax first followed by member selectors. We can remove the reverse on the nameParts as a result (#1118) --- source/ast/Lookup.cpp | 11 ++++------- tests/unittests/ast/TypeTests.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/source/ast/Lookup.cpp b/source/ast/Lookup.cpp index 6827ea1b0..87dc071d3 100644 --- a/source/ast/Lookup.cpp +++ b/source/ast/Lookup.cpp @@ -1340,12 +1340,14 @@ void Lookup::selectChild(const Type& virtualInterface, SourceRange range, SmallVector elementSelects; auto& comp = context.getCompilation(); - for (auto& selector : selectors) { + for (auto& selector : std::views::reverse(selectors)) { if (auto memberSel = std::get_if(&selector)) { NamePlusLoc npl; npl.dotLocation = memberSel->dotLocation; npl.name.text = memberSel->name; npl.name.range = memberSel->nameRange; + std::ranges::reverse(elementSelects); // reverse the element selects since we initially + // saw them in reverse order npl.name.selectors = elementSelects.copy(comp); nameParts.push_back(npl); @@ -1356,13 +1358,8 @@ void Lookup::selectChild(const Type& virtualInterface, SourceRange range, } } - // lookupDownward expects names in reverse order... - SmallVector namePartsReversed(nameParts.size(), UninitializedTag()); - for (auto& npl : std::views::reverse(nameParts)) - namePartsReversed.push_back(npl); - result.found = getVirtualInterfaceTarget(virtualInterface, context, range); - lookupDownward(namePartsReversed, unused, context, LookupFlags::None, result); + lookupDownward(nameParts, unused, context, LookupFlags::None, result); } const ClassType* Lookup::findClass(const NameSyntax& className, const ASTContext& context, diff --git a/tests/unittests/ast/TypeTests.cpp b/tests/unittests/ast/TypeTests.cpp index a96b22ed8..a57e4bab6 100644 --- a/tests/unittests/ast/TypeTests.cpp +++ b/tests/unittests/ast/TypeTests.cpp @@ -2214,3 +2214,33 @@ logic [-2147483648:-2147483649] a; CHECK(diags[1].code == diag::SignedIntegerOverflow); CHECK(diags[2].code == diag::SignedIntegerOverflow); } + +TEST_CASE("Virtual interface element select of member") { + auto tree = SyntaxTree::fromText(R"( + interface iface; + logic [255:0] data[2048]; + logic [255:0] data_3d[2048][128][128]; + endinterface + + class cls1; + virtual iface vif; + endclass + + class cls2; + cls1 c; + logic [255:0] data; + function set(int idx); + c.vif.data[idx] = data; + c.vif.data_3d[idx][64][8] = data; + c.vif.data_3d[idx][64][8][10:0] = data[10:0]; // index + range select + endfunction + endclass + + module top; + endmodule +)"); + + Compilation compilation; + compilation.addSyntaxTree(tree); + NO_COMPILATION_ERRORS; +}