Skip to content

Commit

Permalink
Fix printing of scopes for type aliases in diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Jun 5, 2024
1 parent 2d42130 commit 0371eb7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/ast/types/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ void TypePrinter::visit(const TypeAliasType& type, std::string_view overrideName
if (!overrideName.empty()) {
type.targetType.getType().visit(*this, overrideName);
}
else if (options.elideScopeNames) {
else if (options.elideScopeNames ||
options.anonymousTypeStyle == TypePrintingOptions::FriendlyName) {
type.targetType.getType().visit(*this, type.name);
}
else {
Expand Down
25 changes: 25 additions & 0 deletions tests/unittests/ast/ExpressionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3619,3 +3619,28 @@ endmodule
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::BadConcatExpression);
}

TEST_CASE("Wrong typename in error regress GH #1013") {
auto tree = SyntaxTree::fromText(R"(
module t40;
typedef struct {
logic a;
logic b;
} t;
t x, y, z;
assign z = x & y;
endmodule
)");

Compilation compilation;
compilation.addSyntaxTree(tree);

auto& diags = compilation.getAllDiagnostics();
std::string result = "\n" + report(diags);
CHECK(result == R"(
source:8:14: error: invalid operands to binary expression ('t40.t' and 't40.t')
assign z = x & y;
~ ^ ~
)");
}

0 comments on commit 0371eb7

Please sign in to comment.