Skip to content

Commit

Permalink
Fix a case of false type equivalency (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
povik authored Nov 14, 2024
1 parent 862b51c commit 981c28e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions source/ast/types/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,9 @@ bool Type::isMatching(const Type& rhs) const {
if (l == r)
return true;

if (l->getSyntax() && l->getSyntax() == r->getSyntax() &&
l->getParentScope() == r->getParentScope()) {
if (l->getSyntax() && l->getSyntax() == r->getSyntax() && l->getParentScope() &&
l->getParentScope() == r->getParentScope())
return true;
}

// Special casing for type synonyms: real/realtime
if (l->isFloating() && r->isFloating()) {
Expand Down
28 changes: 28 additions & 0 deletions tests/unittests/ast/TypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2244,3 +2244,31 @@ TEST_CASE("Virtual interface element select of member") {
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

TEST_CASE("Hierarchy-dependent type equivalence") {
auto tree = SyntaxTree::fromText(R"(
interface iface #(parameter int WIDTH = 1)();
typedef struct packed {
bit [3:0] op;
} t;
t [WIDTH-1:0] ready;
endinterface
module top();
iface #(.WIDTH(1)) if1();
iface #(.WIDTH(2)) if2();
endmodule
)");

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

const InstanceBodySymbol& top = compilation.getRoot().lookupName<InstanceSymbol>("top").body;
const Type* type1 =
&top.lookupName<InstanceSymbol>("if1").body.lookupName<VariableSymbol>("ready").getType();
const Type* type2 =
&top.lookupName<InstanceSymbol>("if2").body.lookupName<VariableSymbol>("ready").getType();

CHECK(!type1->isEquivalent(*type2));
}

0 comments on commit 981c28e

Please sign in to comment.