Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a case of false type equivalency #1175

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}