Skip to content

Commit

Permalink
Fix off-by-one in symbol lookup location for detecting parameters use…
Browse files Browse the repository at this point in the history
…d before declared
  • Loading branch information
MikePopoloski committed Apr 29, 2023
1 parent c50549a commit a5240e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/ast/Symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ std::optional<bool> Symbol::isDeclaredBefore(LookupLocation target) const {
// If target wasn't in a direct scope of any of our own parents,
// repeat the process walking up target's scopes.
sym = &target.getScope()->asSymbol();
ll = LookupLocation::before(*sym);
ll = LookupLocation::after(*sym);

while ((scope = ll.getScope()) != nullptr && sym->kind != SymbolKind::CompilationUnit) {
if (auto it = locMap.find(scope); it != locMap.end())
return it->second < ll;

sym = &scope->asSymbol();
ll = LookupLocation::before(*sym);
ll = LookupLocation::after(*sym);
}

return std::nullopt;
Expand Down
18 changes: 18 additions & 0 deletions tests/unittests/HierarchyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2254,3 +2254,21 @@ endmodule
CHECK(diags[0].code == diag::InfoTask);
CHECK(diags[1].code == diag::InfoTask);
}

TEST_CASE("Hierarchical parameter lookup location regress") {
auto tree = SyntaxTree::fromText(R"(
interface I;
parameter int P = 6;
function automatic int getP; return P; endfunction
endinterface
module m;
I i();
localparam int a = i.getP();
endmodule
)");

Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

0 comments on commit a5240e3

Please sign in to comment.