Skip to content

Commit

Permalink
Add checking of predicate in conditional constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Dec 15, 2024
1 parent e8c9895 commit 10b0843
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/ast/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ Constraint& ConditionalConstraint::fromSyntax(const ConditionalConstraintSyntax&
return badConstraint(comp, result);

ConstraintExprVisitor visitor(context, /* isSoft */ false);
if (!pred.visit(visitor))
if (!pred.visit(visitor) || !context.requireBooleanConvertible(pred))
return badConstraint(comp, result);

return *result;
Expand Down
10 changes: 9 additions & 1 deletion tests/unittests/ast/WarningTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,17 +787,25 @@ module m;
initial if (i & 2) begin end
initial if (i ^ 2) begin end
endmodule
class C;
int a;
constraint c {
if (a) {}
}
endclass
)");

Compilation compilation;
compilation.addSyntaxTree(tree);

auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 4);
REQUIRE(diags.size() == 5);
CHECK(diags[0].code == diag::FloatBoolConv);
CHECK(diags[1].code == diag::IntBoolConv);
CHECK(diags[2].code == diag::IntBoolConv);
CHECK(diags[3].code == diag::FloatBoolConv);
CHECK(diags[4].code == diag::IntBoolConv);
}

TEST_CASE("Useless cast warnings") {
Expand Down

0 comments on commit 10b0843

Please sign in to comment.