Skip to content

Commit

Permalink
Fix spurious warnings inside an unused generic class that instantiate…
Browse files Browse the repository at this point in the history
…s the default specialization of itself
  • Loading branch information
MikePopoloski committed Oct 5, 2024
1 parent 903ed2a commit d80d984
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
5 changes: 1 addition & 4 deletions source/ast/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ const Expression& Expression::bindLValue(const ExpressionSyntax& lhs, const Type
// Create a placeholder expression that will carry the type of the rhs.
// Nothing will ever actually look at this expression, it's there only
// to fill the space in the created AssignmentExpression.
SourceRange rhsRange{location, location};
auto rhsExpr = comp.emplace<EmptyArgumentExpression>(rhs, rhsRange);
if (rhsExpr->bad())
return badExpr(comp, nullptr);
auto rhsExpr = comp.emplace<EmptyArgumentExpression>(rhs, SourceRange{location, location});

auto instance = context.getInstance();
Expression* lhsExpr;
Expand Down
38 changes: 38 additions & 0 deletions tests/unittests/ast/ClassTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3445,3 +3445,41 @@ endmodule
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

TEST_CASE("Unused var checking intersected with generic classes -- GH #1142") {
auto tree = SyntaxTree::fromText(R"(
class A #(type T);
endclass
class B #(type T);
task get((* unused *) output T t);
endtask
endclass
class C #(type T = int);
B #(T) b;
(* unused *) typedef A #(C) unused;
task test();
T t;
forever begin
b.get(t);
process(t);
end
endtask
function void process((* unused *) T t);
endfunction
endclass
module top;
endmodule
)");

CompilationOptions coptions;
coptions.flags = CompilationFlags::None;

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

0 comments on commit d80d984

Please sign in to comment.