diff --git a/source/ast/Expression.cpp b/source/ast/Expression.cpp index a5c93cbe6..8fc0ca64e 100644 --- a/source/ast/Expression.cpp +++ b/source/ast/Expression.cpp @@ -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(rhs, rhsRange); - if (rhsExpr->bad()) - return badExpr(comp, nullptr); + auto rhsExpr = comp.emplace(rhs, SourceRange{location, location}); auto instance = context.getInstance(); Expression* lhsExpr; diff --git a/tests/unittests/ast/ClassTests.cpp b/tests/unittests/ast/ClassTests.cpp index 3ebb6a039..7d6ffb06f 100644 --- a/tests/unittests/ast/ClassTests.cpp +++ b/tests/unittests/ast/ClassTests.cpp @@ -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; +}